
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
        <link rel="canonical" href="https://pytorch-widedeep.readthedocs.io/pytorch-widedeep/trainer.html">
      
      
        <link rel="prev" href="callbacks.html">
      
      
        <link rel="next" href="bayesian_trainer.html">
      
      
      <link rel="icon" href="../assets/images/favicon.ico">
      <meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.43">
    
    
      
        <title>Trainer - pytorch_widedeep</title>
      
    
    
      <link rel="stylesheet" href="../assets/stylesheets/main.0253249f.min.css">
      
        
        <link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
      
      


    
    
      
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
      <link rel="stylesheet" href="../assets/_mkdocstrings.css">
    
      <link rel="stylesheet" href="../stylesheets/extra.css">
    
    <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="red" data-md-color-accent="deep-orange">
  
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#training-multimodal-deep-learning-models" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

  

<header class="md-header md-header--shadow md-header--lifted" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../index.html" title="pytorch_widedeep" class="md-header__button md-logo" aria-label="pytorch_widedeep" data-md-component="logo">
      
  <img src="../assets/images/widedeep_logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            pytorch_widedeep
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              Trainer
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="red" data-md-color-accent="deep-orange"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_0">
    
      <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg>
      </label>
    
  
    
    
    
    <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="red" data-md-color-accent="deep-orange"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_1">
    
      <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg>
      </label>
    
  
</form>
      
    
    
      <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
        
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
          
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://github.com/jrzaurin/pytorch-widedeep" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
  </div>
  <div class="md-source__repository">
    pytorch_widedeep
  </div>
</a>
      </div>
    
  </nav>
  
    
      
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-grid">
    <ul class="md-tabs__list">
      
        
  
  
  
    <li class="md-tabs__item">
      <a href="../index.html" class="md-tabs__link">
        
  
    
  
  Home

      </a>
    </li>
  

      
        
  
  
  
    <li class="md-tabs__item">
      <a href="../installation.html" class="md-tabs__link">
        
  
    
  
  Installation

      </a>
    </li>
  

      
        
  
  
  
    <li class="md-tabs__item">
      <a href="../quick_start.html" class="md-tabs__link">
        
  
    
  
  Quick Start

      </a>
    </li>
  

      
        
  
  
    
  
  
    
    
      
  
  
    
  
  
    
    
      <li class="md-tabs__item md-tabs__item--active">
        <a href="utils/index.html" class="md-tabs__link">
          
  
    
  
  Pytorch-widedeep

        </a>
      </li>
    
  

    
  

      
        
  
  
  
    
    
      <li class="md-tabs__item">
        <a href="../examples/01_preprocessors_and_utils.html" class="md-tabs__link">
          
  
    
  
  Examples

        </a>
      </li>
    
  

      
        
  
  
  
    <li class="md-tabs__item">
      <a href="../contributing.html" class="md-tabs__link">
        
  
    
  
  Contributing

      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
    
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    


  


  

<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../index.html" title="pytorch_widedeep" class="md-nav__button md-logo" aria-label="pytorch_widedeep" data-md-component="logo">
      
  <img src="../assets/images/widedeep_logo.png" alt="logo">

    </a>
    pytorch_widedeep
  </label>
  
    <div class="md-nav__source">
      <a href="https://github.com/jrzaurin/pytorch-widedeep" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81"/></svg>
  </div>
  <div class="md-source__repository">
    pytorch_widedeep
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../index.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Home
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../installation.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Installation
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../quick_start.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Quick Start
  </span>
  

      </a>
    </li>
  

    
      
      
  
  
    
  
  
  
    
    
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
    
    
      
        
        
      
      
    
    
    <li class="md-nav__item md-nav__item--active md-nav__item--section md-nav__item--nested">
      
        
        
        <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" checked>
        
          
          <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="">
            
  
  <span class="md-ellipsis">
    Pytorch-widedeep
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
          <label class="md-nav__title" for="__nav_4">
            <span class="md-nav__icon md-icon"></span>
            Pytorch-widedeep
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    
    
      
        
          
        
      
        
      
        
      
        
      
        
      
    
    
      
      
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
          
        
        <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4_1" >
        
          
          
          <div class="md-nav__link md-nav__container">
            <a href="utils/index.html" class="md-nav__link ">
              
  
  <span class="md-ellipsis">
    Utils
  </span>
  

            </a>
            
              
              <label class="md-nav__link " for="__nav_4_1" id="__nav_4_1_label" tabindex="0">
                <span class="md-nav__icon md-icon"></span>
              </label>
            
          </div>
        
        <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_1_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_4_1">
            <span class="md-nav__icon md-icon"></span>
            Utils
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="utils/deeptabular_utils.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Deeptabular utils
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="utils/fastai_transforms.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Fastai transforms
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="utils/image_utils.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Image utils
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="utils/text_utils.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Text utils
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="preprocessing.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Preprocessing
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="load_from_folder.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Load From Folder
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="model_components.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Model Components
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="the_rec_module.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    The Rec Module
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="bayesian_models.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Bayesian models
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="losses.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Losses
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="metrics.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Metrics
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="dataloaders.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Dataloaders
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="callbacks.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Callbacks
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
    
  
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          
  
  <span class="md-ellipsis">
    Trainer
  </span>
  

          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="trainer.html" class="md-nav__link md-nav__link--active">
        
  
  <span class="md-ellipsis">
    Trainer
  </span>
  

      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#pytorch_widedeep.training.Trainer" class="md-nav__link">
    <span class="md-ellipsis">
      Trainer
    </span>
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="bayesian_trainer.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Bayesian Trainer
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="self_supervised_pretraining.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Self Supervised Pretraining
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="tab2vec.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Tab2Vec
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    
    
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
    
    
      
      
    
    
    <li class="md-nav__item md-nav__item--nested">
      
        
        
          
        
        <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_5" >
        
          
          <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
            
  
  <span class="md-ellipsis">
    Examples
  </span>
  

            <span class="md-nav__icon md-icon"></span>
          </label>
        
        <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
          <label class="md-nav__title" for="__nav_5">
            <span class="md-nav__icon md-icon"></span>
            Examples
          </label>
          <ul class="md-nav__list" data-md-scrollfix>
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/01_preprocessors_and_utils.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    01_preprocessors_and_utils
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/02_model_components.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    02_model_components
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/03_binary_classification_with_defaults.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    03_binary_classification_with_defaults
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/04_regression_with_images_and_text.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    04_regression_with_images_and_text
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/05_save_and_load_model_and_artifacts.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    05_save_and_load_model_and_artifacts
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/06_finetune_and_warmup.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    06_finetune_and_warmup
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/07_custom_components.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    07_custom_components
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/08_custom_dataLoader_imbalanced_dataset.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    08_custom_dataLoader_imbalanced_dataset
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/09_extracting_embeddings.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    09_extracting_embeddings
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/10_3rd_party_integration-RayTune_WnB.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    10_3rd_party_integration-RayTune_WnB
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/11_auc_multiclass.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    11_auc_multiclass
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/12_ZILNLoss_origkeras_vs_pytorch_widedeep.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    12_ZILNLoss_origkeras_vs_pytorch_widedeep
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/13_model_uncertainty_prediction.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    13_model_uncertainty_prediction
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/14_bayesian_models.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    14_bayesian_models
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/15_Self_Supervised_Pretraning_pt1.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    15_Self-Supervised Pre-Training pt 1
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/15_Self_Supervised_Pretraning_pt2.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    15_Self-Supervised Pre-Training pt 2
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/16_Usign_a_custom_hugging_face_model.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    16_Usign-a-custom-hugging-face-model
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/17_feature_importance_via_attention_weights.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    17_feature_importance_via_attention_weights
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/18_wide_and_deep_for_recsys_pt1.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    18_wide_and_deep_for_recsys_pt1
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/18_wide_and_deep_for_recsys_pt2.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    18_wide_and_deep_for_recsys_pt2
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/19_load_from_folder_functionality.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    19_load_from_folder_functionality
  </span>
  

      </a>
    </li>
  

              
            
              
                
  
  
  
  
    <li class="md-nav__item">
      <a href="../examples/20_Using_huggingface_within_widedeep.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    20-Using-huggingface-within-widedeep
  </span>
  

      </a>
    </li>
  

              
            
          </ul>
        </nav>
      
    </li>
  

    
      
      
  
  
  
  
    <li class="md-nav__item">
      <a href="../contributing.html" class="md-nav__link">
        
  
  <span class="md-ellipsis">
    Contributing
  </span>
  

      </a>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  
  


<h1 id="training-multimodal-deep-learning-models">Training multimodal Deep Learning Models<a class="headerlink" href="#training-multimodal-deep-learning-models" title="Permanent link">&para;</a></h1>
<p>Here is the documentation for the <code>Trainer</code> class, that will do all the heavy lifting.</p>
<p>Trainer is also available from <code>pytorch-widedeep</code> directly, for example, one could do:</p>
<div class="highlight"><pre><span></span><code>    from pytorch-widedeep.training import Trainer
</code></pre></div>
<p>or also:</p>
<div class="highlight"><pre><span></span><code>    from pytorch-widedeep import Trainer
</code></pre></div>


<div class="doc doc-object doc-class">



<h2 id="pytorch_widedeep.training.Trainer" class="doc doc-heading">
            <span class="doc doc-object-name doc-class-name">Trainer</span>


<a href="#pytorch_widedeep.training.Trainer" class="headerlink" title="Permanent link">&para;</a></h2>


    <div class="doc doc-contents first">
            <p class="doc doc-class-bases">
              Bases: <code><span title="pytorch_widedeep.training._base_trainer.BaseTrainer">BaseTrainer</span></code></p>


        <p>Class to set the of attributes that will be used during the
training process.</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>model</code>
            </td>
            <td>
                  <code><a class="autorefs autorefs-internal" title="pytorch_widedeep.wdtypes.WideDeep" href="model_components.html#pytorch_widedeep.models.wide_deep.WideDeep">WideDeep</a></code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>An object of class <code>WideDeep</code></p>
              </div>
            </td>
            <td>
                <em>required</em>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>objective</code>
            </td>
            <td>
                  <code>str</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Defines the objective, loss or cost function. <br/></p>
<p>Param aliases: <code>loss_function</code>, <code>loss_fn</code>, <code>loss</code>,
<code>cost_function</code>, <code>cost_fn</code>, <code>cost</code>. <br/></p>
<p>Possible values are:</p>
<ul>
<li>
<p><code>binary</code>, aliases: <code>logistic</code>, <code>binary_logloss</code>, <code>binary_cross_entropy</code></p>
</li>
<li>
<p><code>binary_focal_loss</code></p>
</li>
<li>
<p><code>multiclass</code>, aliases: <code>multi_logloss</code>, <code>cross_entropy</code>, <code>categorical_cross_entropy</code>,</p>
</li>
<li>
<p><code>multiclass_focal_loss</code></p>
</li>
<li>
<p><code>regression</code>, aliases: <code>mse</code>, <code>l2</code>, <code>mean_squared_error</code></p>
</li>
<li>
<p><code>mean_absolute_error</code>, aliases: <code>mae</code>, <code>l1</code></p>
</li>
<li>
<p><code>mean_squared_log_error</code>, aliases: <code>msle</code></p>
</li>
<li>
<p><code>root_mean_squared_error</code>, aliases:  <code>rmse</code></p>
</li>
<li>
<p><code>root_mean_squared_log_error</code>, aliases: <code>rmsle</code></p>
</li>
<li>
<p><code>zero_inflated_lognormal</code>, aliases: <code>ziln</code></p>
</li>
<li>
<p><code>quantile</code></p>
</li>
<li>
<p><code>tweedie</code></p>
</li>
<li>
<p><code>multitarget</code>, aliases: <code>multi_target</code></p>
</li>
</ul>
<p><strong>NOTE</strong>: For <code>multitarget</code> a custom loss function must be passed</p>
              </div>
            </td>
            <td>
                <em>required</em>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>custom_loss_function</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="torch.nn.Module">Module</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>It is possible to pass a custom loss function. See for example
<code>pytorch_widedeep.losses.FocalLoss</code> for the required structure of the
object or the Examples section in this documentation or in the repo.
Note that if <code>custom_loss_function</code> is not <code>None</code>, <code>objective</code> must
be <em>'binary'</em>, <em>'multiclass'</em> or <em>'regression'</em>, consistent with the
loss function</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>optimizers</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.wdtypes.Optimizer">Optimizer</span>, <span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.wdtypes.Optimizer">Optimizer</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.wdtypes.Optimizer">Optimizer</span>]]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <ul>
<li>An instance of Pytorch's <code>Optimizer</code> object
  (e.g. <code>torch.optim.Adam()</code>) or</li>
<li>a dictionary where there keys are the model components (i.e.
  <em>'wide'</em>, <em>'deeptabular'</em>, <em>'deeptext'</em>, <em>'deepimage'</em>
  and/or <em>'deephead'</em>)  and the values are the corresponding
  optimizers or list of optimizers if multiple models are used for
  the given data mode (e.g. two text columns/models for the deeptext
  component). If multiple optimizers are used the
  dictionary <strong>MUST</strong> contain an optimizer per model component.</li>
</ul>
<p>if no optimizers are passed it will default to <code>Adam</code> for all
model components</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>lr_schedulers</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.wdtypes.LRScheduler">LRScheduler</span>, <span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.wdtypes.LRScheduler">LRScheduler</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.wdtypes.LRScheduler">LRScheduler</span>]]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <ul>
<li>An instance of Pytorch's <code>LRScheduler</code> object (e.g
  <code>torch.optim.lr_scheduler.StepLR(opt, step_size=5)</code>) or</li>
<li>a dictionary where there keys are the model componenst (i.e. <em>'wide'</em>,
  <em>'deeptabular'</em>, <em>'deeptext'</em>, <em>'deepimage'</em> and/or <em>'deephead'</em>) and the
  values are the corresponding learning rate schedulers or list of
    learning rate schedulers if multiple models are used for the given
    data mode (e.g. two text columns/models for the deeptext component).</li>
</ul>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>initializers</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.initializers.Initializer">Initializer</span>, <span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.initializers.Initializer">Initializer</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.initializers.Initializer">Initializer</span>]]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <ul>
<li>An instance of an <code>Initializer</code> object see <code>pytorch-widedeep.initializers</code> or</li>
<li>a dictionary where there keys are the model components (i.e. <em>'wide'</em>,
  <em>'deeptabular'</em>, <em>'deeptext'</em>, <em>'deepimage'</em> and/or <em>'deephead'</em>)
  and the values are the corresponding initializers or list of
    initializers if multiple models are used for the given data mode (e.g.
    two text columns/models for the deeptext component).</li>
</ul>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>transforms</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.wdtypes.Transforms">Transforms</span>]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>List with <code>torchvision.transforms</code> to be applied to the image
component of the model (i.e. <code>deepimage</code>) See
<a href="https://pytorch.org/docs/stable/torchvision/transforms.html">torchvision transforms</a>.</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>callbacks</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.callbacks.Callback">Callback</span>]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>List with <code>Callback</code> objects. The three callbacks available in
<code>pytorch-widedeep</code> are: <code>LRHistory</code>, <code>ModelCheckpoint</code> and
<code>EarlyStopping</code>. The <code>History</code> and the <code>LRShedulerCallback</code> callbacks
are used by default. This can also be a custom callback as long as
the object of type <code>Callback</code>. See
<code>pytorch_widedeep.callbacks.Callback</code> or the examples folder in the
repo.</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>metrics</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="pytorch_widedeep.metrics.Metric">Metric</span>], <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="torchmetrics.Metric">Metric</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <ul>
<li>List of objects of type <code>Metric</code>. Metrics available are:
  <code>Accuracy</code>, <code>Precision</code>, <code>Recall</code>, <code>FBetaScore</code>,
  <code>F1Score</code> and <code>R2Score</code>. This can also be a custom metric as long
  as it is an object of type <code>Metric</code>. See
  <code>pytorch_widedeep.metrics.Metric</code> or the examples folder in the
  repo</li>
<li>List of objects of type <code>torchmetrics.Metric</code>. This can be any
  metric from torchmetrics library
  <a href="https://torchmetrics.readthedocs.io/en/latest/">Examples</a>.
  This can also be a custom metric as long as
  it is an object of type <code>Metric</code>. See
  <a href="https://torchmetrics.readthedocs.io/en/latest/">the instructions</a>.</li>
</ul>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>verbose</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Verbosity level. If set to 0 nothing will be printed during training</p>
              </div>
            </td>
            <td>
                  <code>1</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>seed</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Random seed to be used internally for train/test split</p>
              </div>
            </td>
            <td>
                  <code>1</code>
            </td>
          </tr>
      </tbody>
    </table>


<p><span class="doc-section-title">Other Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td><code>**kwargs</code></td>
            <td>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Other infrequently used arguments that can also be passed as kwargs are:</p>
<ul>
<li>
<p><strong>device</strong>: <code>str</code><br/>
    string indicating the device. One of <em>'cpu'</em>, <em>'gpu'</em> or 'mps' if
    run on a Mac with Apple silicon or AMD GPU(s)</p>
</li>
<li>
<p><strong>num_workers</strong>: <code>int</code><br/>
    number of workers to be used internally by the data loaders</p>
</li>
<li>
<p><strong>lambda_sparse</strong>: <code>float</code><br/>
    lambda sparse parameter in case the <code>deeptabular</code> component is <code>TabNet</code></p>
</li>
<li>
<p><strong>class_weight</strong>: <code>List[float]</code><br/>
    This is the <code>weight</code> or <code>pos_weight</code> parameter in
    <code>CrossEntropyLoss</code> and <code>BCEWithLogitsLoss</code>, depending on whether</p>
</li>
<li><strong>reducelronplateau_criterion</strong>: <code>str</code>
    This sets the criterion that will be used by the lr scheduler to
    take a step: One of <em>'loss'</em> or <em>'metric'</em>. The ReduceLROnPlateau
    learning rate is a bit particular.</li>
</ul>
              </div>
            </td>
          </tr>
      </tbody>
    </table>


<p><span class="doc-section-title">Attributes:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td><code><span title="pytorch_widedeep.training.Trainer.cyclic_lr">cyclic_lr</span></code></td>
            <td>
                  <code>bool</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Attribute that indicates if any of the lr_schedulers is cyclic_lr
(i.e. <code>CyclicLR</code> or
<code>OneCycleLR</code>). See <a href="https://pytorch.org/docs/stable/optim.html">Pytorch schedulers</a>.</p>
              </div>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td><code><span title="pytorch_widedeep.training.Trainer.feature_importance">feature_importance</span></code></td>
            <td>
                  <code>dict</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>dict where the keys are the column names and the values are the
corresponding feature importances. This attribute will only exist
if the <code>deeptabular</code> component is a Tabnet model.</p>
              </div>
            </td>
          </tr>
      </tbody>
    </table>


<p><span class="doc-section-title">Examples:</span></p>
    <div class="highlight"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">torch</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">torchvision.transforms</span> <span class="kn">import</span> <span class="n">ToTensor</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># wide deep imports</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pytorch_widedeep.callbacks</span> <span class="kn">import</span> <span class="n">EarlyStopping</span><span class="p">,</span> <span class="n">LRHistory</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pytorch_widedeep.initializers</span> <span class="kn">import</span> <span class="n">KaimingNormal</span><span class="p">,</span> <span class="n">KaimingUniform</span><span class="p">,</span> <span class="n">Normal</span><span class="p">,</span> <span class="n">Uniform</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pytorch_widedeep.models</span> <span class="kn">import</span> <span class="n">TabResnet</span><span class="p">,</span> <span class="n">Vision</span><span class="p">,</span> <span class="n">BasicRNN</span><span class="p">,</span> <span class="n">Wide</span><span class="p">,</span> <span class="n">WideDeep</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pytorch_widedeep</span> <span class="kn">import</span> <span class="n">Trainer</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">embed_input</span> <span class="o">=</span> <span class="p">[(</span><span class="n">u</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">)</span> <span class="k">for</span> <span class="n">u</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">([</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">][:</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">8</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">column_idx</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">v</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">])}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wide</span> <span class="o">=</span> <span class="n">Wide</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># build the model</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">deeptabular</span> <span class="o">=</span> <span class="n">TabResnet</span><span class="p">(</span><span class="n">blocks_dims</span><span class="o">=</span><span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="n">column_idx</span><span class="o">=</span><span class="n">column_idx</span><span class="p">,</span> <span class="n">cat_embed_input</span><span class="o">=</span><span class="n">embed_input</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">deeptext</span> <span class="o">=</span> <span class="n">BasicRNN</span><span class="p">(</span><span class="n">vocab_size</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">embed_dim</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">padding_idx</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">deepimage</span> <span class="o">=</span> <span class="n">Vision</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">model</span> <span class="o">=</span> <span class="n">WideDeep</span><span class="p">(</span><span class="n">wide</span><span class="o">=</span><span class="n">wide</span><span class="p">,</span> <span class="n">deeptabular</span><span class="o">=</span><span class="n">deeptabular</span><span class="p">,</span> <span class="n">deeptext</span><span class="o">=</span><span class="n">deeptext</span><span class="p">,</span> <span class="n">deepimage</span><span class="o">=</span><span class="n">deepimage</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># set optimizers and schedulers</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wide_opt</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">Adam</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">wide</span><span class="o">.</span><span class="n">parameters</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">deep_opt</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">AdamW</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">deeptabular</span><span class="o">.</span><span class="n">parameters</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">text_opt</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">Adam</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">deeptext</span><span class="o">.</span><span class="n">parameters</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">img_opt</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">AdamW</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">deepimage</span><span class="o">.</span><span class="n">parameters</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">wide_sch</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">lr_scheduler</span><span class="o">.</span><span class="n">StepLR</span><span class="p">(</span><span class="n">wide_opt</span><span class="p">,</span> <span class="n">step_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">deep_sch</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">lr_scheduler</span><span class="o">.</span><span class="n">StepLR</span><span class="p">(</span><span class="n">deep_opt</span><span class="p">,</span> <span class="n">step_size</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">text_sch</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">lr_scheduler</span><span class="o">.</span><span class="n">StepLR</span><span class="p">(</span><span class="n">text_opt</span><span class="p">,</span> <span class="n">step_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">img_sch</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">optim</span><span class="o">.</span><span class="n">lr_scheduler</span><span class="o">.</span><span class="n">StepLR</span><span class="p">(</span><span class="n">img_opt</span><span class="p">,</span> <span class="n">step_size</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">optimizers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;wide&quot;</span><span class="p">:</span> <span class="n">wide_opt</span><span class="p">,</span> <span class="s2">&quot;deeptabular&quot;</span><span class="p">:</span> <span class="n">deep_opt</span><span class="p">,</span> <span class="s2">&quot;deeptext&quot;</span><span class="p">:</span> <span class="n">text_opt</span><span class="p">,</span> <span class="s2">&quot;deepimage&quot;</span><span class="p">:</span> <span class="n">img_opt</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schedulers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;wide&quot;</span><span class="p">:</span> <span class="n">wide_sch</span><span class="p">,</span> <span class="s2">&quot;deeptabular&quot;</span><span class="p">:</span> <span class="n">deep_sch</span><span class="p">,</span> <span class="s2">&quot;deeptext&quot;</span><span class="p">:</span> <span class="n">text_sch</span><span class="p">,</span> <span class="s2">&quot;deepimage&quot;</span><span class="p">:</span> <span class="n">img_sch</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># set initializers and callbacks</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">initializers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;wide&quot;</span><span class="p">:</span> <span class="n">Uniform</span><span class="p">,</span> <span class="s2">&quot;deeptabular&quot;</span><span class="p">:</span> <span class="n">Normal</span><span class="p">,</span> <span class="s2">&quot;deeptext&quot;</span><span class="p">:</span> <span class="n">KaimingNormal</span><span class="p">,</span> <span class="s2">&quot;deepimage&quot;</span><span class="p">:</span> <span class="n">KaimingUniform</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">transforms</span> <span class="o">=</span> <span class="p">[</span><span class="n">ToTensor</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">callbacks</span> <span class="o">=</span> <span class="p">[</span><span class="n">LRHistory</span><span class="p">(</span><span class="n">n_epochs</span><span class="o">=</span><span class="mi">4</span><span class="p">),</span> <span class="n">EarlyStopping</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># set the trainer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">trainer</span> <span class="o">=</span> <span class="n">Trainer</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">objective</span><span class="o">=</span><span class="s2">&quot;regression&quot;</span><span class="p">,</span> <span class="n">initializers</span><span class="o">=</span><span class="n">initializers</span><span class="p">,</span> <span class="n">optimizers</span><span class="o">=</span><span class="n">optimizers</span><span class="p">,</span>
<span class="gp">... </span><span class="n">lr_schedulers</span><span class="o">=</span><span class="n">schedulers</span><span class="p">,</span> <span class="n">callbacks</span><span class="o">=</span><span class="n">callbacks</span><span class="p">,</span> <span class="n">transforms</span><span class="o">=</span><span class="n">transforms</span><span class="p">)</span>
</code></pre></div>






              <details class="quote">
                <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
                <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">  43</span>
<span class="normal">  44</span>
<span class="normal">  45</span>
<span class="normal">  46</span>
<span class="normal">  47</span>
<span class="normal">  48</span>
<span class="normal">  49</span>
<span class="normal">  50</span>
<span class="normal">  51</span>
<span class="normal">  52</span>
<span class="normal">  53</span>
<span class="normal">  54</span>
<span class="normal">  55</span>
<span class="normal">  56</span>
<span class="normal">  57</span>
<span class="normal">  58</span>
<span class="normal">  59</span>
<span class="normal">  60</span>
<span class="normal">  61</span>
<span class="normal">  62</span>
<span class="normal">  63</span>
<span class="normal">  64</span>
<span class="normal">  65</span>
<span class="normal">  66</span>
<span class="normal">  67</span>
<span class="normal">  68</span>
<span class="normal">  69</span>
<span class="normal">  70</span>
<span class="normal">  71</span>
<span class="normal">  72</span>
<span class="normal">  73</span>
<span class="normal">  74</span>
<span class="normal">  75</span>
<span class="normal">  76</span>
<span class="normal">  77</span>
<span class="normal">  78</span>
<span class="normal">  79</span>
<span class="normal">  80</span>
<span class="normal">  81</span>
<span class="normal">  82</span>
<span class="normal">  83</span>
<span class="normal">  84</span>
<span class="normal">  85</span>
<span class="normal">  86</span>
<span class="normal">  87</span>
<span class="normal">  88</span>
<span class="normal">  89</span>
<span class="normal">  90</span>
<span class="normal">  91</span>
<span class="normal">  92</span>
<span class="normal">  93</span>
<span class="normal">  94</span>
<span class="normal">  95</span>
<span class="normal">  96</span>
<span class="normal">  97</span>
<span class="normal">  98</span>
<span class="normal">  99</span>
<span class="normal"> 100</span>
<span class="normal"> 101</span>
<span class="normal"> 102</span>
<span class="normal"> 103</span>
<span class="normal"> 104</span>
<span class="normal"> 105</span>
<span class="normal"> 106</span>
<span class="normal"> 107</span>
<span class="normal"> 108</span>
<span class="normal"> 109</span>
<span class="normal"> 110</span>
<span class="normal"> 111</span>
<span class="normal"> 112</span>
<span class="normal"> 113</span>
<span class="normal"> 114</span>
<span class="normal"> 115</span>
<span class="normal"> 116</span>
<span class="normal"> 117</span>
<span class="normal"> 118</span>
<span class="normal"> 119</span>
<span class="normal"> 120</span>
<span class="normal"> 121</span>
<span class="normal"> 122</span>
<span class="normal"> 123</span>
<span class="normal"> 124</span>
<span class="normal"> 125</span>
<span class="normal"> 126</span>
<span class="normal"> 127</span>
<span class="normal"> 128</span>
<span class="normal"> 129</span>
<span class="normal"> 130</span>
<span class="normal"> 131</span>
<span class="normal"> 132</span>
<span class="normal"> 133</span>
<span class="normal"> 134</span>
<span class="normal"> 135</span>
<span class="normal"> 136</span>
<span class="normal"> 137</span>
<span class="normal"> 138</span>
<span class="normal"> 139</span>
<span class="normal"> 140</span>
<span class="normal"> 141</span>
<span class="normal"> 142</span>
<span class="normal"> 143</span>
<span class="normal"> 144</span>
<span class="normal"> 145</span>
<span class="normal"> 146</span>
<span class="normal"> 147</span>
<span class="normal"> 148</span>
<span class="normal"> 149</span>
<span class="normal"> 150</span>
<span class="normal"> 151</span>
<span class="normal"> 152</span>
<span class="normal"> 153</span>
<span class="normal"> 154</span>
<span class="normal"> 155</span>
<span class="normal"> 156</span>
<span class="normal"> 157</span>
<span class="normal"> 158</span>
<span class="normal"> 159</span>
<span class="normal"> 160</span>
<span class="normal"> 161</span>
<span class="normal"> 162</span>
<span class="normal"> 163</span>
<span class="normal"> 164</span>
<span class="normal"> 165</span>
<span class="normal"> 166</span>
<span class="normal"> 167</span>
<span class="normal"> 168</span>
<span class="normal"> 169</span>
<span class="normal"> 170</span>
<span class="normal"> 171</span>
<span class="normal"> 172</span>
<span class="normal"> 173</span>
<span class="normal"> 174</span>
<span class="normal"> 175</span>
<span class="normal"> 176</span>
<span class="normal"> 177</span>
<span class="normal"> 178</span>
<span class="normal"> 179</span>
<span class="normal"> 180</span>
<span class="normal"> 181</span>
<span class="normal"> 182</span>
<span class="normal"> 183</span>
<span class="normal"> 184</span>
<span class="normal"> 185</span>
<span class="normal"> 186</span>
<span class="normal"> 187</span>
<span class="normal"> 188</span>
<span class="normal"> 189</span>
<span class="normal"> 190</span>
<span class="normal"> 191</span>
<span class="normal"> 192</span>
<span class="normal"> 193</span>
<span class="normal"> 194</span>
<span class="normal"> 195</span>
<span class="normal"> 196</span>
<span class="normal"> 197</span>
<span class="normal"> 198</span>
<span class="normal"> 199</span>
<span class="normal"> 200</span>
<span class="normal"> 201</span>
<span class="normal"> 202</span>
<span class="normal"> 203</span>
<span class="normal"> 204</span>
<span class="normal"> 205</span>
<span class="normal"> 206</span>
<span class="normal"> 207</span>
<span class="normal"> 208</span>
<span class="normal"> 209</span>
<span class="normal"> 210</span>
<span class="normal"> 211</span>
<span class="normal"> 212</span>
<span class="normal"> 213</span>
<span class="normal"> 214</span>
<span class="normal"> 215</span>
<span class="normal"> 216</span>
<span class="normal"> 217</span>
<span class="normal"> 218</span>
<span class="normal"> 219</span>
<span class="normal"> 220</span>
<span class="normal"> 221</span>
<span class="normal"> 222</span>
<span class="normal"> 223</span>
<span class="normal"> 224</span>
<span class="normal"> 225</span>
<span class="normal"> 226</span>
<span class="normal"> 227</span>
<span class="normal"> 228</span>
<span class="normal"> 229</span>
<span class="normal"> 230</span>
<span class="normal"> 231</span>
<span class="normal"> 232</span>
<span class="normal"> 233</span>
<span class="normal"> 234</span>
<span class="normal"> 235</span>
<span class="normal"> 236</span>
<span class="normal"> 237</span>
<span class="normal"> 238</span>
<span class="normal"> 239</span>
<span class="normal"> 240</span>
<span class="normal"> 241</span>
<span class="normal"> 242</span>
<span class="normal"> 243</span>
<span class="normal"> 244</span>
<span class="normal"> 245</span>
<span class="normal"> 246</span>
<span class="normal"> 247</span>
<span class="normal"> 248</span>
<span class="normal"> 249</span>
<span class="normal"> 250</span>
<span class="normal"> 251</span>
<span class="normal"> 252</span>
<span class="normal"> 253</span>
<span class="normal"> 254</span>
<span class="normal"> 255</span>
<span class="normal"> 256</span>
<span class="normal"> 257</span>
<span class="normal"> 258</span>
<span class="normal"> 259</span>
<span class="normal"> 260</span>
<span class="normal"> 261</span>
<span class="normal"> 262</span>
<span class="normal"> 263</span>
<span class="normal"> 264</span>
<span class="normal"> 265</span>
<span class="normal"> 266</span>
<span class="normal"> 267</span>
<span class="normal"> 268</span>
<span class="normal"> 269</span>
<span class="normal"> 270</span>
<span class="normal"> 271</span>
<span class="normal"> 272</span>
<span class="normal"> 273</span>
<span class="normal"> 274</span>
<span class="normal"> 275</span>
<span class="normal"> 276</span>
<span class="normal"> 277</span>
<span class="normal"> 278</span>
<span class="normal"> 279</span>
<span class="normal"> 280</span>
<span class="normal"> 281</span>
<span class="normal"> 282</span>
<span class="normal"> 283</span>
<span class="normal"> 284</span>
<span class="normal"> 285</span>
<span class="normal"> 286</span>
<span class="normal"> 287</span>
<span class="normal"> 288</span>
<span class="normal"> 289</span>
<span class="normal"> 290</span>
<span class="normal"> 291</span>
<span class="normal"> 292</span>
<span class="normal"> 293</span>
<span class="normal"> 294</span>
<span class="normal"> 295</span>
<span class="normal"> 296</span>
<span class="normal"> 297</span>
<span class="normal"> 298</span>
<span class="normal"> 299</span>
<span class="normal"> 300</span>
<span class="normal"> 301</span>
<span class="normal"> 302</span>
<span class="normal"> 303</span>
<span class="normal"> 304</span>
<span class="normal"> 305</span>
<span class="normal"> 306</span>
<span class="normal"> 307</span>
<span class="normal"> 308</span>
<span class="normal"> 309</span>
<span class="normal"> 310</span>
<span class="normal"> 311</span>
<span class="normal"> 312</span>
<span class="normal"> 313</span>
<span class="normal"> 314</span>
<span class="normal"> 315</span>
<span class="normal"> 316</span>
<span class="normal"> 317</span>
<span class="normal"> 318</span>
<span class="normal"> 319</span>
<span class="normal"> 320</span>
<span class="normal"> 321</span>
<span class="normal"> 322</span>
<span class="normal"> 323</span>
<span class="normal"> 324</span>
<span class="normal"> 325</span>
<span class="normal"> 326</span>
<span class="normal"> 327</span>
<span class="normal"> 328</span>
<span class="normal"> 329</span>
<span class="normal"> 330</span>
<span class="normal"> 331</span>
<span class="normal"> 332</span>
<span class="normal"> 333</span>
<span class="normal"> 334</span>
<span class="normal"> 335</span>
<span class="normal"> 336</span>
<span class="normal"> 337</span>
<span class="normal"> 338</span>
<span class="normal"> 339</span>
<span class="normal"> 340</span>
<span class="normal"> 341</span>
<span class="normal"> 342</span>
<span class="normal"> 343</span>
<span class="normal"> 344</span>
<span class="normal"> 345</span>
<span class="normal"> 346</span>
<span class="normal"> 347</span>
<span class="normal"> 348</span>
<span class="normal"> 349</span>
<span class="normal"> 350</span>
<span class="normal"> 351</span>
<span class="normal"> 352</span>
<span class="normal"> 353</span>
<span class="normal"> 354</span>
<span class="normal"> 355</span>
<span class="normal"> 356</span>
<span class="normal"> 357</span>
<span class="normal"> 358</span>
<span class="normal"> 359</span>
<span class="normal"> 360</span>
<span class="normal"> 361</span>
<span class="normal"> 362</span>
<span class="normal"> 363</span>
<span class="normal"> 364</span>
<span class="normal"> 365</span>
<span class="normal"> 366</span>
<span class="normal"> 367</span>
<span class="normal"> 368</span>
<span class="normal"> 369</span>
<span class="normal"> 370</span>
<span class="normal"> 371</span>
<span class="normal"> 372</span>
<span class="normal"> 373</span>
<span class="normal"> 374</span>
<span class="normal"> 375</span>
<span class="normal"> 376</span>
<span class="normal"> 377</span>
<span class="normal"> 378</span>
<span class="normal"> 379</span>
<span class="normal"> 380</span>
<span class="normal"> 381</span>
<span class="normal"> 382</span>
<span class="normal"> 383</span>
<span class="normal"> 384</span>
<span class="normal"> 385</span>
<span class="normal"> 386</span>
<span class="normal"> 387</span>
<span class="normal"> 388</span>
<span class="normal"> 389</span>
<span class="normal"> 390</span>
<span class="normal"> 391</span>
<span class="normal"> 392</span>
<span class="normal"> 393</span>
<span class="normal"> 394</span>
<span class="normal"> 395</span>
<span class="normal"> 396</span>
<span class="normal"> 397</span>
<span class="normal"> 398</span>
<span class="normal"> 399</span>
<span class="normal"> 400</span>
<span class="normal"> 401</span>
<span class="normal"> 402</span>
<span class="normal"> 403</span>
<span class="normal"> 404</span>
<span class="normal"> 405</span>
<span class="normal"> 406</span>
<span class="normal"> 407</span>
<span class="normal"> 408</span>
<span class="normal"> 409</span>
<span class="normal"> 410</span>
<span class="normal"> 411</span>
<span class="normal"> 412</span>
<span class="normal"> 413</span>
<span class="normal"> 414</span>
<span class="normal"> 415</span>
<span class="normal"> 416</span>
<span class="normal"> 417</span>
<span class="normal"> 418</span>
<span class="normal"> 419</span>
<span class="normal"> 420</span>
<span class="normal"> 421</span>
<span class="normal"> 422</span>
<span class="normal"> 423</span>
<span class="normal"> 424</span>
<span class="normal"> 425</span>
<span class="normal"> 426</span>
<span class="normal"> 427</span>
<span class="normal"> 428</span>
<span class="normal"> 429</span>
<span class="normal"> 430</span>
<span class="normal"> 431</span>
<span class="normal"> 432</span>
<span class="normal"> 433</span>
<span class="normal"> 434</span>
<span class="normal"> 435</span>
<span class="normal"> 436</span>
<span class="normal"> 437</span>
<span class="normal"> 438</span>
<span class="normal"> 439</span>
<span class="normal"> 440</span>
<span class="normal"> 441</span>
<span class="normal"> 442</span>
<span class="normal"> 443</span>
<span class="normal"> 444</span>
<span class="normal"> 445</span>
<span class="normal"> 446</span>
<span class="normal"> 447</span>
<span class="normal"> 448</span>
<span class="normal"> 449</span>
<span class="normal"> 450</span>
<span class="normal"> 451</span>
<span class="normal"> 452</span>
<span class="normal"> 453</span>
<span class="normal"> 454</span>
<span class="normal"> 455</span>
<span class="normal"> 456</span>
<span class="normal"> 457</span>
<span class="normal"> 458</span>
<span class="normal"> 459</span>
<span class="normal"> 460</span>
<span class="normal"> 461</span>
<span class="normal"> 462</span>
<span class="normal"> 463</span>
<span class="normal"> 464</span>
<span class="normal"> 465</span>
<span class="normal"> 466</span>
<span class="normal"> 467</span>
<span class="normal"> 468</span>
<span class="normal"> 469</span>
<span class="normal"> 470</span>
<span class="normal"> 471</span>
<span class="normal"> 472</span>
<span class="normal"> 473</span>
<span class="normal"> 474</span>
<span class="normal"> 475</span>
<span class="normal"> 476</span>
<span class="normal"> 477</span>
<span class="normal"> 478</span>
<span class="normal"> 479</span>
<span class="normal"> 480</span>
<span class="normal"> 481</span>
<span class="normal"> 482</span>
<span class="normal"> 483</span>
<span class="normal"> 484</span>
<span class="normal"> 485</span>
<span class="normal"> 486</span>
<span class="normal"> 487</span>
<span class="normal"> 488</span>
<span class="normal"> 489</span>
<span class="normal"> 490</span>
<span class="normal"> 491</span>
<span class="normal"> 492</span>
<span class="normal"> 493</span>
<span class="normal"> 494</span>
<span class="normal"> 495</span>
<span class="normal"> 496</span>
<span class="normal"> 497</span>
<span class="normal"> 498</span>
<span class="normal"> 499</span>
<span class="normal"> 500</span>
<span class="normal"> 501</span>
<span class="normal"> 502</span>
<span class="normal"> 503</span>
<span class="normal"> 504</span>
<span class="normal"> 505</span>
<span class="normal"> 506</span>
<span class="normal"> 507</span>
<span class="normal"> 508</span>
<span class="normal"> 509</span>
<span class="normal"> 510</span>
<span class="normal"> 511</span>
<span class="normal"> 512</span>
<span class="normal"> 513</span>
<span class="normal"> 514</span>
<span class="normal"> 515</span>
<span class="normal"> 516</span>
<span class="normal"> 517</span>
<span class="normal"> 518</span>
<span class="normal"> 519</span>
<span class="normal"> 520</span>
<span class="normal"> 521</span>
<span class="normal"> 522</span>
<span class="normal"> 523</span>
<span class="normal"> 524</span>
<span class="normal"> 525</span>
<span class="normal"> 526</span>
<span class="normal"> 527</span>
<span class="normal"> 528</span>
<span class="normal"> 529</span>
<span class="normal"> 530</span>
<span class="normal"> 531</span>
<span class="normal"> 532</span>
<span class="normal"> 533</span>
<span class="normal"> 534</span>
<span class="normal"> 535</span>
<span class="normal"> 536</span>
<span class="normal"> 537</span>
<span class="normal"> 538</span>
<span class="normal"> 539</span>
<span class="normal"> 540</span>
<span class="normal"> 541</span>
<span class="normal"> 542</span>
<span class="normal"> 543</span>
<span class="normal"> 544</span>
<span class="normal"> 545</span>
<span class="normal"> 546</span>
<span class="normal"> 547</span>
<span class="normal"> 548</span>
<span class="normal"> 549</span>
<span class="normal"> 550</span>
<span class="normal"> 551</span>
<span class="normal"> 552</span>
<span class="normal"> 553</span>
<span class="normal"> 554</span>
<span class="normal"> 555</span>
<span class="normal"> 556</span>
<span class="normal"> 557</span>
<span class="normal"> 558</span>
<span class="normal"> 559</span>
<span class="normal"> 560</span>
<span class="normal"> 561</span>
<span class="normal"> 562</span>
<span class="normal"> 563</span>
<span class="normal"> 564</span>
<span class="normal"> 565</span>
<span class="normal"> 566</span>
<span class="normal"> 567</span>
<span class="normal"> 568</span>
<span class="normal"> 569</span>
<span class="normal"> 570</span>
<span class="normal"> 571</span>
<span class="normal"> 572</span>
<span class="normal"> 573</span>
<span class="normal"> 574</span>
<span class="normal"> 575</span>
<span class="normal"> 576</span>
<span class="normal"> 577</span>
<span class="normal"> 578</span>
<span class="normal"> 579</span>
<span class="normal"> 580</span>
<span class="normal"> 581</span>
<span class="normal"> 582</span>
<span class="normal"> 583</span>
<span class="normal"> 584</span>
<span class="normal"> 585</span>
<span class="normal"> 586</span>
<span class="normal"> 587</span>
<span class="normal"> 588</span>
<span class="normal"> 589</span>
<span class="normal"> 590</span>
<span class="normal"> 591</span>
<span class="normal"> 592</span>
<span class="normal"> 593</span>
<span class="normal"> 594</span>
<span class="normal"> 595</span>
<span class="normal"> 596</span>
<span class="normal"> 597</span>
<span class="normal"> 598</span>
<span class="normal"> 599</span>
<span class="normal"> 600</span>
<span class="normal"> 601</span>
<span class="normal"> 602</span>
<span class="normal"> 603</span>
<span class="normal"> 604</span>
<span class="normal"> 605</span>
<span class="normal"> 606</span>
<span class="normal"> 607</span>
<span class="normal"> 608</span>
<span class="normal"> 609</span>
<span class="normal"> 610</span>
<span class="normal"> 611</span>
<span class="normal"> 612</span>
<span class="normal"> 613</span>
<span class="normal"> 614</span>
<span class="normal"> 615</span>
<span class="normal"> 616</span>
<span class="normal"> 617</span>
<span class="normal"> 618</span>
<span class="normal"> 619</span>
<span class="normal"> 620</span>
<span class="normal"> 621</span>
<span class="normal"> 622</span>
<span class="normal"> 623</span>
<span class="normal"> 624</span>
<span class="normal"> 625</span>
<span class="normal"> 626</span>
<span class="normal"> 627</span>
<span class="normal"> 628</span>
<span class="normal"> 629</span>
<span class="normal"> 630</span>
<span class="normal"> 631</span>
<span class="normal"> 632</span>
<span class="normal"> 633</span>
<span class="normal"> 634</span>
<span class="normal"> 635</span>
<span class="normal"> 636</span>
<span class="normal"> 637</span>
<span class="normal"> 638</span>
<span class="normal"> 639</span>
<span class="normal"> 640</span>
<span class="normal"> 641</span>
<span class="normal"> 642</span>
<span class="normal"> 643</span>
<span class="normal"> 644</span>
<span class="normal"> 645</span>
<span class="normal"> 646</span>
<span class="normal"> 647</span>
<span class="normal"> 648</span>
<span class="normal"> 649</span>
<span class="normal"> 650</span>
<span class="normal"> 651</span>
<span class="normal"> 652</span>
<span class="normal"> 653</span>
<span class="normal"> 654</span>
<span class="normal"> 655</span>
<span class="normal"> 656</span>
<span class="normal"> 657</span>
<span class="normal"> 658</span>
<span class="normal"> 659</span>
<span class="normal"> 660</span>
<span class="normal"> 661</span>
<span class="normal"> 662</span>
<span class="normal"> 663</span>
<span class="normal"> 664</span>
<span class="normal"> 665</span>
<span class="normal"> 666</span>
<span class="normal"> 667</span>
<span class="normal"> 668</span>
<span class="normal"> 669</span>
<span class="normal"> 670</span>
<span class="normal"> 671</span>
<span class="normal"> 672</span>
<span class="normal"> 673</span>
<span class="normal"> 674</span>
<span class="normal"> 675</span>
<span class="normal"> 676</span>
<span class="normal"> 677</span>
<span class="normal"> 678</span>
<span class="normal"> 679</span>
<span class="normal"> 680</span>
<span class="normal"> 681</span>
<span class="normal"> 682</span>
<span class="normal"> 683</span>
<span class="normal"> 684</span>
<span class="normal"> 685</span>
<span class="normal"> 686</span>
<span class="normal"> 687</span>
<span class="normal"> 688</span>
<span class="normal"> 689</span>
<span class="normal"> 690</span>
<span class="normal"> 691</span>
<span class="normal"> 692</span>
<span class="normal"> 693</span>
<span class="normal"> 694</span>
<span class="normal"> 695</span>
<span class="normal"> 696</span>
<span class="normal"> 697</span>
<span class="normal"> 698</span>
<span class="normal"> 699</span>
<span class="normal"> 700</span>
<span class="normal"> 701</span>
<span class="normal"> 702</span>
<span class="normal"> 703</span>
<span class="normal"> 704</span>
<span class="normal"> 705</span>
<span class="normal"> 706</span>
<span class="normal"> 707</span>
<span class="normal"> 708</span>
<span class="normal"> 709</span>
<span class="normal"> 710</span>
<span class="normal"> 711</span>
<span class="normal"> 712</span>
<span class="normal"> 713</span>
<span class="normal"> 714</span>
<span class="normal"> 715</span>
<span class="normal"> 716</span>
<span class="normal"> 717</span>
<span class="normal"> 718</span>
<span class="normal"> 719</span>
<span class="normal"> 720</span>
<span class="normal"> 721</span>
<span class="normal"> 722</span>
<span class="normal"> 723</span>
<span class="normal"> 724</span>
<span class="normal"> 725</span>
<span class="normal"> 726</span>
<span class="normal"> 727</span>
<span class="normal"> 728</span>
<span class="normal"> 729</span>
<span class="normal"> 730</span>
<span class="normal"> 731</span>
<span class="normal"> 732</span>
<span class="normal"> 733</span>
<span class="normal"> 734</span>
<span class="normal"> 735</span>
<span class="normal"> 736</span>
<span class="normal"> 737</span>
<span class="normal"> 738</span>
<span class="normal"> 739</span>
<span class="normal"> 740</span>
<span class="normal"> 741</span>
<span class="normal"> 742</span>
<span class="normal"> 743</span>
<span class="normal"> 744</span>
<span class="normal"> 745</span>
<span class="normal"> 746</span>
<span class="normal"> 747</span>
<span class="normal"> 748</span>
<span class="normal"> 749</span>
<span class="normal"> 750</span>
<span class="normal"> 751</span>
<span class="normal"> 752</span>
<span class="normal"> 753</span>
<span class="normal"> 754</span>
<span class="normal"> 755</span>
<span class="normal"> 756</span>
<span class="normal"> 757</span>
<span class="normal"> 758</span>
<span class="normal"> 759</span>
<span class="normal"> 760</span>
<span class="normal"> 761</span>
<span class="normal"> 762</span>
<span class="normal"> 763</span>
<span class="normal"> 764</span>
<span class="normal"> 765</span>
<span class="normal"> 766</span>
<span class="normal"> 767</span>
<span class="normal"> 768</span>
<span class="normal"> 769</span>
<span class="normal"> 770</span>
<span class="normal"> 771</span>
<span class="normal"> 772</span>
<span class="normal"> 773</span>
<span class="normal"> 774</span>
<span class="normal"> 775</span>
<span class="normal"> 776</span>
<span class="normal"> 777</span>
<span class="normal"> 778</span>
<span class="normal"> 779</span>
<span class="normal"> 780</span>
<span class="normal"> 781</span>
<span class="normal"> 782</span>
<span class="normal"> 783</span>
<span class="normal"> 784</span>
<span class="normal"> 785</span>
<span class="normal"> 786</span>
<span class="normal"> 787</span>
<span class="normal"> 788</span>
<span class="normal"> 789</span>
<span class="normal"> 790</span>
<span class="normal"> 791</span>
<span class="normal"> 792</span>
<span class="normal"> 793</span>
<span class="normal"> 794</span>
<span class="normal"> 795</span>
<span class="normal"> 796</span>
<span class="normal"> 797</span>
<span class="normal"> 798</span>
<span class="normal"> 799</span>
<span class="normal"> 800</span>
<span class="normal"> 801</span>
<span class="normal"> 802</span>
<span class="normal"> 803</span>
<span class="normal"> 804</span>
<span class="normal"> 805</span>
<span class="normal"> 806</span>
<span class="normal"> 807</span>
<span class="normal"> 808</span>
<span class="normal"> 809</span>
<span class="normal"> 810</span>
<span class="normal"> 811</span>
<span class="normal"> 812</span>
<span class="normal"> 813</span>
<span class="normal"> 814</span>
<span class="normal"> 815</span>
<span class="normal"> 816</span>
<span class="normal"> 817</span>
<span class="normal"> 818</span>
<span class="normal"> 819</span>
<span class="normal"> 820</span>
<span class="normal"> 821</span>
<span class="normal"> 822</span>
<span class="normal"> 823</span>
<span class="normal"> 824</span>
<span class="normal"> 825</span>
<span class="normal"> 826</span>
<span class="normal"> 827</span>
<span class="normal"> 828</span>
<span class="normal"> 829</span>
<span class="normal"> 830</span>
<span class="normal"> 831</span>
<span class="normal"> 832</span>
<span class="normal"> 833</span>
<span class="normal"> 834</span>
<span class="normal"> 835</span>
<span class="normal"> 836</span>
<span class="normal"> 837</span>
<span class="normal"> 838</span>
<span class="normal"> 839</span>
<span class="normal"> 840</span>
<span class="normal"> 841</span>
<span class="normal"> 842</span>
<span class="normal"> 843</span>
<span class="normal"> 844</span>
<span class="normal"> 845</span>
<span class="normal"> 846</span>
<span class="normal"> 847</span>
<span class="normal"> 848</span>
<span class="normal"> 849</span>
<span class="normal"> 850</span>
<span class="normal"> 851</span>
<span class="normal"> 852</span>
<span class="normal"> 853</span>
<span class="normal"> 854</span>
<span class="normal"> 855</span>
<span class="normal"> 856</span>
<span class="normal"> 857</span>
<span class="normal"> 858</span>
<span class="normal"> 859</span>
<span class="normal"> 860</span>
<span class="normal"> 861</span>
<span class="normal"> 862</span>
<span class="normal"> 863</span>
<span class="normal"> 864</span>
<span class="normal"> 865</span>
<span class="normal"> 866</span>
<span class="normal"> 867</span>
<span class="normal"> 868</span>
<span class="normal"> 869</span>
<span class="normal"> 870</span>
<span class="normal"> 871</span>
<span class="normal"> 872</span>
<span class="normal"> 873</span>
<span class="normal"> 874</span>
<span class="normal"> 875</span>
<span class="normal"> 876</span>
<span class="normal"> 877</span>
<span class="normal"> 878</span>
<span class="normal"> 879</span>
<span class="normal"> 880</span>
<span class="normal"> 881</span>
<span class="normal"> 882</span>
<span class="normal"> 883</span>
<span class="normal"> 884</span>
<span class="normal"> 885</span>
<span class="normal"> 886</span>
<span class="normal"> 887</span>
<span class="normal"> 888</span>
<span class="normal"> 889</span>
<span class="normal"> 890</span>
<span class="normal"> 891</span>
<span class="normal"> 892</span>
<span class="normal"> 893</span>
<span class="normal"> 894</span>
<span class="normal"> 895</span>
<span class="normal"> 896</span>
<span class="normal"> 897</span>
<span class="normal"> 898</span>
<span class="normal"> 899</span>
<span class="normal"> 900</span>
<span class="normal"> 901</span>
<span class="normal"> 902</span>
<span class="normal"> 903</span>
<span class="normal"> 904</span>
<span class="normal"> 905</span>
<span class="normal"> 906</span>
<span class="normal"> 907</span>
<span class="normal"> 908</span>
<span class="normal"> 909</span>
<span class="normal"> 910</span>
<span class="normal"> 911</span>
<span class="normal"> 912</span>
<span class="normal"> 913</span>
<span class="normal"> 914</span>
<span class="normal"> 915</span>
<span class="normal"> 916</span>
<span class="normal"> 917</span>
<span class="normal"> 918</span>
<span class="normal"> 919</span>
<span class="normal"> 920</span>
<span class="normal"> 921</span>
<span class="normal"> 922</span>
<span class="normal"> 923</span>
<span class="normal"> 924</span>
<span class="normal"> 925</span>
<span class="normal"> 926</span>
<span class="normal"> 927</span>
<span class="normal"> 928</span>
<span class="normal"> 929</span>
<span class="normal"> 930</span>
<span class="normal"> 931</span>
<span class="normal"> 932</span>
<span class="normal"> 933</span>
<span class="normal"> 934</span>
<span class="normal"> 935</span>
<span class="normal"> 936</span>
<span class="normal"> 937</span>
<span class="normal"> 938</span>
<span class="normal"> 939</span>
<span class="normal"> 940</span>
<span class="normal"> 941</span>
<span class="normal"> 942</span>
<span class="normal"> 943</span>
<span class="normal"> 944</span>
<span class="normal"> 945</span>
<span class="normal"> 946</span>
<span class="normal"> 947</span>
<span class="normal"> 948</span>
<span class="normal"> 949</span>
<span class="normal"> 950</span>
<span class="normal"> 951</span>
<span class="normal"> 952</span>
<span class="normal"> 953</span>
<span class="normal"> 954</span>
<span class="normal"> 955</span>
<span class="normal"> 956</span>
<span class="normal"> 957</span>
<span class="normal"> 958</span>
<span class="normal"> 959</span>
<span class="normal"> 960</span>
<span class="normal"> 961</span>
<span class="normal"> 962</span>
<span class="normal"> 963</span>
<span class="normal"> 964</span>
<span class="normal"> 965</span>
<span class="normal"> 966</span>
<span class="normal"> 967</span>
<span class="normal"> 968</span>
<span class="normal"> 969</span>
<span class="normal"> 970</span>
<span class="normal"> 971</span>
<span class="normal"> 972</span>
<span class="normal"> 973</span>
<span class="normal"> 974</span>
<span class="normal"> 975</span>
<span class="normal"> 976</span>
<span class="normal"> 977</span>
<span class="normal"> 978</span>
<span class="normal"> 979</span>
<span class="normal"> 980</span>
<span class="normal"> 981</span>
<span class="normal"> 982</span>
<span class="normal"> 983</span>
<span class="normal"> 984</span>
<span class="normal"> 985</span>
<span class="normal"> 986</span>
<span class="normal"> 987</span>
<span class="normal"> 988</span>
<span class="normal"> 989</span>
<span class="normal"> 990</span>
<span class="normal"> 991</span>
<span class="normal"> 992</span>
<span class="normal"> 993</span>
<span class="normal"> 994</span>
<span class="normal"> 995</span>
<span class="normal"> 996</span>
<span class="normal"> 997</span>
<span class="normal"> 998</span>
<span class="normal"> 999</span>
<span class="normal">1000</span>
<span class="normal">1001</span>
<span class="normal">1002</span>
<span class="normal">1003</span>
<span class="normal">1004</span>
<span class="normal">1005</span>
<span class="normal">1006</span>
<span class="normal">1007</span>
<span class="normal">1008</span>
<span class="normal">1009</span>
<span class="normal">1010</span>
<span class="normal">1011</span>
<span class="normal">1012</span>
<span class="normal">1013</span>
<span class="normal">1014</span>
<span class="normal">1015</span>
<span class="normal">1016</span>
<span class="normal">1017</span>
<span class="normal">1018</span>
<span class="normal">1019</span>
<span class="normal">1020</span>
<span class="normal">1021</span>
<span class="normal">1022</span>
<span class="normal">1023</span>
<span class="normal">1024</span>
<span class="normal">1025</span>
<span class="normal">1026</span>
<span class="normal">1027</span>
<span class="normal">1028</span>
<span class="normal">1029</span>
<span class="normal">1030</span>
<span class="normal">1031</span>
<span class="normal">1032</span>
<span class="normal">1033</span>
<span class="normal">1034</span>
<span class="normal">1035</span>
<span class="normal">1036</span>
<span class="normal">1037</span>
<span class="normal">1038</span>
<span class="normal">1039</span>
<span class="normal">1040</span>
<span class="normal">1041</span>
<span class="normal">1042</span>
<span class="normal">1043</span>
<span class="normal">1044</span>
<span class="normal">1045</span>
<span class="normal">1046</span>
<span class="normal">1047</span>
<span class="normal">1048</span>
<span class="normal">1049</span>
<span class="normal">1050</span>
<span class="normal">1051</span>
<span class="normal">1052</span>
<span class="normal">1053</span>
<span class="normal">1054</span>
<span class="normal">1055</span>
<span class="normal">1056</span>
<span class="normal">1057</span>
<span class="normal">1058</span>
<span class="normal">1059</span>
<span class="normal">1060</span>
<span class="normal">1061</span>
<span class="normal">1062</span>
<span class="normal">1063</span>
<span class="normal">1064</span>
<span class="normal">1065</span>
<span class="normal">1066</span>
<span class="normal">1067</span>
<span class="normal">1068</span>
<span class="normal">1069</span>
<span class="normal">1070</span>
<span class="normal">1071</span>
<span class="normal">1072</span>
<span class="normal">1073</span>
<span class="normal">1074</span>
<span class="normal">1075</span>
<span class="normal">1076</span>
<span class="normal">1077</span>
<span class="normal">1078</span>
<span class="normal">1079</span>
<span class="normal">1080</span>
<span class="normal">1081</span>
<span class="normal">1082</span>
<span class="normal">1083</span>
<span class="normal">1084</span>
<span class="normal">1085</span>
<span class="normal">1086</span>
<span class="normal">1087</span>
<span class="normal">1088</span>
<span class="normal">1089</span>
<span class="normal">1090</span>
<span class="normal">1091</span>
<span class="normal">1092</span>
<span class="normal">1093</span>
<span class="normal">1094</span>
<span class="normal">1095</span>
<span class="normal">1096</span>
<span class="normal">1097</span>
<span class="normal">1098</span>
<span class="normal">1099</span>
<span class="normal">1100</span>
<span class="normal">1101</span>
<span class="normal">1102</span>
<span class="normal">1103</span>
<span class="normal">1104</span>
<span class="normal">1105</span>
<span class="normal">1106</span>
<span class="normal">1107</span>
<span class="normal">1108</span>
<span class="normal">1109</span>
<span class="normal">1110</span>
<span class="normal">1111</span>
<span class="normal">1112</span>
<span class="normal">1113</span>
<span class="normal">1114</span>
<span class="normal">1115</span>
<span class="normal">1116</span>
<span class="normal">1117</span>
<span class="normal">1118</span>
<span class="normal">1119</span>
<span class="normal">1120</span>
<span class="normal">1121</span>
<span class="normal">1122</span>
<span class="normal">1123</span>
<span class="normal">1124</span>
<span class="normal">1125</span>
<span class="normal">1126</span>
<span class="normal">1127</span>
<span class="normal">1128</span>
<span class="normal">1129</span>
<span class="normal">1130</span>
<span class="normal">1131</span>
<span class="normal">1132</span>
<span class="normal">1133</span>
<span class="normal">1134</span>
<span class="normal">1135</span>
<span class="normal">1136</span>
<span class="normal">1137</span>
<span class="normal">1138</span>
<span class="normal">1139</span>
<span class="normal">1140</span>
<span class="normal">1141</span>
<span class="normal">1142</span>
<span class="normal">1143</span>
<span class="normal">1144</span>
<span class="normal">1145</span>
<span class="normal">1146</span>
<span class="normal">1147</span>
<span class="normal">1148</span>
<span class="normal">1149</span>
<span class="normal">1150</span>
<span class="normal">1151</span>
<span class="normal">1152</span>
<span class="normal">1153</span>
<span class="normal">1154</span>
<span class="normal">1155</span>
<span class="normal">1156</span>
<span class="normal">1157</span>
<span class="normal">1158</span>
<span class="normal">1159</span>
<span class="normal">1160</span>
<span class="normal">1161</span>
<span class="normal">1162</span>
<span class="normal">1163</span>
<span class="normal">1164</span>
<span class="normal">1165</span>
<span class="normal">1166</span>
<span class="normal">1167</span>
<span class="normal">1168</span>
<span class="normal">1169</span>
<span class="normal">1170</span>
<span class="normal">1171</span>
<span class="normal">1172</span>
<span class="normal">1173</span>
<span class="normal">1174</span>
<span class="normal">1175</span>
<span class="normal">1176</span>
<span class="normal">1177</span>
<span class="normal">1178</span>
<span class="normal">1179</span>
<span class="normal">1180</span>
<span class="normal">1181</span>
<span class="normal">1182</span>
<span class="normal">1183</span>
<span class="normal">1184</span>
<span class="normal">1185</span>
<span class="normal">1186</span>
<span class="normal">1187</span>
<span class="normal">1188</span>
<span class="normal">1189</span>
<span class="normal">1190</span>
<span class="normal">1191</span>
<span class="normal">1192</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">class</span> <span class="nc">Trainer</span><span class="p">(</span><span class="n">BaseTrainer</span><span class="p">):</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Class to set the of attributes that will be used during the</span>
<span class="sd">    training process.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    model: `WideDeep`</span>
<span class="sd">        An object of class `WideDeep`</span>
<span class="sd">    objective: str</span>
<span class="sd">        Defines the objective, loss or cost function. &lt;br/&gt;</span>

<span class="sd">        Param aliases: `loss_function`, `loss_fn`, `loss`,</span>
<span class="sd">        `cost_function`, `cost_fn`, `cost`. &lt;br/&gt;</span>

<span class="sd">        Possible values are:</span>

<span class="sd">        - `binary`, aliases: `logistic`, `binary_logloss`, `binary_cross_entropy`</span>

<span class="sd">        - `binary_focal_loss`</span>

<span class="sd">        - `multiclass`, aliases: `multi_logloss`, `cross_entropy`, `categorical_cross_entropy`,</span>

<span class="sd">        - `multiclass_focal_loss`</span>

<span class="sd">        - `regression`, aliases: `mse`, `l2`, `mean_squared_error`</span>

<span class="sd">        - `mean_absolute_error`, aliases: `mae`, `l1`</span>

<span class="sd">        - `mean_squared_log_error`, aliases: `msle`</span>

<span class="sd">        - `root_mean_squared_error`, aliases:  `rmse`</span>

<span class="sd">        - `root_mean_squared_log_error`, aliases: `rmsle`</span>

<span class="sd">        - `zero_inflated_lognormal`, aliases: `ziln`</span>

<span class="sd">        - `quantile`</span>

<span class="sd">        - `tweedie`</span>

<span class="sd">        - `multitarget`, aliases: `multi_target`</span>

<span class="sd">        **NOTE**: For `multitarget` a custom loss function must be passed</span>
<span class="sd">    custom_loss_function: `nn.Module`. Optional, default = None</span>
<span class="sd">        It is possible to pass a custom loss function. See for example</span>
<span class="sd">        `pytorch_widedeep.losses.FocalLoss` for the required structure of the</span>
<span class="sd">        object or the Examples section in this documentation or in the repo.</span>
<span class="sd">        Note that if `custom_loss_function` is not `None`, `objective` must</span>
<span class="sd">        be _&#39;binary&#39;_, _&#39;multiclass&#39;_ or _&#39;regression&#39;_, consistent with the</span>
<span class="sd">        loss function</span>
<span class="sd">    optimizers: `Optimizer` or dict. Optional, default=None</span>
<span class="sd">        - An instance of Pytorch&#39;s `Optimizer` object</span>
<span class="sd">          (e.g. `torch.optim.Adam()`) or</span>
<span class="sd">        - a dictionary where there keys are the model components (i.e.</span>
<span class="sd">          _&#39;wide&#39;_, _&#39;deeptabular&#39;_, _&#39;deeptext&#39;_, _&#39;deepimage&#39;_</span>
<span class="sd">          and/or _&#39;deephead&#39;_)  and the values are the corresponding</span>
<span class="sd">          optimizers or list of optimizers if multiple models are used for</span>
<span class="sd">          the given data mode (e.g. two text columns/models for the deeptext</span>
<span class="sd">          component). If multiple optimizers are used the</span>
<span class="sd">          dictionary **MUST** contain an optimizer per model component.</span>

<span class="sd">        if no optimizers are passed it will default to `Adam` for all</span>
<span class="sd">        model components</span>
<span class="sd">    lr_schedulers: `LRScheduler` or dict. Optional, default=None</span>
<span class="sd">        - An instance of Pytorch&#39;s `LRScheduler` object (e.g</span>
<span class="sd">          `torch.optim.lr_scheduler.StepLR(opt, step_size=5)`) or</span>
<span class="sd">        - a dictionary where there keys are the model componenst (i.e. _&#39;wide&#39;_,</span>
<span class="sd">          _&#39;deeptabular&#39;_, _&#39;deeptext&#39;_, _&#39;deepimage&#39;_ and/or _&#39;deephead&#39;_) and the</span>
<span class="sd">          values are the corresponding learning rate schedulers or list of</span>
<span class="sd">            learning rate schedulers if multiple models are used for the given</span>
<span class="sd">            data mode (e.g. two text columns/models for the deeptext component).</span>
<span class="sd">    initializers: `Initializer` or dict. Optional, default=None</span>
<span class="sd">        - An instance of an `Initializer` object see `pytorch-widedeep.initializers` or</span>
<span class="sd">        - a dictionary where there keys are the model components (i.e. _&#39;wide&#39;_,</span>
<span class="sd">          _&#39;deeptabular&#39;_, _&#39;deeptext&#39;_, _&#39;deepimage&#39;_ and/or _&#39;deephead&#39;_)</span>
<span class="sd">          and the values are the corresponding initializers or list of</span>
<span class="sd">            initializers if multiple models are used for the given data mode (e.g.</span>
<span class="sd">            two text columns/models for the deeptext component).</span>
<span class="sd">    transforms: List. Optional, default=None</span>
<span class="sd">        List with `torchvision.transforms` to be applied to the image</span>
<span class="sd">        component of the model (i.e. `deepimage`) See</span>
<span class="sd">        [torchvision transforms](https://pytorch.org/docs/stable/torchvision/transforms.html).</span>
<span class="sd">    callbacks: List. Optional, default=None</span>
<span class="sd">        List with `Callback` objects. The three callbacks available in</span>
<span class="sd">        `pytorch-widedeep` are: `LRHistory`, `ModelCheckpoint` and</span>
<span class="sd">        `EarlyStopping`. The `History` and the `LRShedulerCallback` callbacks</span>
<span class="sd">        are used by default. This can also be a custom callback as long as</span>
<span class="sd">        the object of type `Callback`. See</span>
<span class="sd">        `pytorch_widedeep.callbacks.Callback` or the examples folder in the</span>
<span class="sd">        repo.</span>
<span class="sd">    metrics: List. Optional, default=None</span>
<span class="sd">        - List of objects of type `Metric`. Metrics available are:</span>
<span class="sd">          `Accuracy`, `Precision`, `Recall`, `FBetaScore`,</span>
<span class="sd">          `F1Score` and `R2Score`. This can also be a custom metric as long</span>
<span class="sd">          as it is an object of type `Metric`. See</span>
<span class="sd">          `pytorch_widedeep.metrics.Metric` or the examples folder in the</span>
<span class="sd">          repo</span>
<span class="sd">        - List of objects of type `torchmetrics.Metric`. This can be any</span>
<span class="sd">          metric from torchmetrics library</span>
<span class="sd">          [Examples](https://torchmetrics.readthedocs.io/en/latest/).</span>
<span class="sd">          This can also be a custom metric as long as</span>
<span class="sd">          it is an object of type `Metric`. See</span>
<span class="sd">          [the instructions](https://torchmetrics.readthedocs.io/en/latest/).</span>
<span class="sd">    verbose: int, default=1</span>
<span class="sd">        Verbosity level. If set to 0 nothing will be printed during training</span>
<span class="sd">    seed: int, default=1</span>
<span class="sd">        Random seed to be used internally for train/test split</span>

<span class="sd">    Other Parameters</span>
<span class="sd">    ----------------</span>
<span class="sd">    **kwargs: dict</span>
<span class="sd">        Other infrequently used arguments that can also be passed as kwargs are:</span>

<span class="sd">        - **device**: `str`&lt;br/&gt;</span>
<span class="sd">            string indicating the device. One of _&#39;cpu&#39;_, _&#39;gpu&#39;_ or &#39;mps&#39; if</span>
<span class="sd">            run on a Mac with Apple silicon or AMD GPU(s)</span>

<span class="sd">        - **num_workers**: `int`&lt;br/&gt;</span>
<span class="sd">            number of workers to be used internally by the data loaders</span>

<span class="sd">        - **lambda_sparse**: `float`&lt;br/&gt;</span>
<span class="sd">            lambda sparse parameter in case the `deeptabular` component is `TabNet`</span>

<span class="sd">        - **class_weight**: `List[float]`&lt;br/&gt;</span>
<span class="sd">            This is the `weight` or `pos_weight` parameter in</span>
<span class="sd">            `CrossEntropyLoss` and `BCEWithLogitsLoss`, depending on whether</span>
<span class="sd">        - **reducelronplateau_criterion**: `str`</span>
<span class="sd">            This sets the criterion that will be used by the lr scheduler to</span>
<span class="sd">            take a step: One of _&#39;loss&#39;_ or _&#39;metric&#39;_. The ReduceLROnPlateau</span>
<span class="sd">            learning rate is a bit particular.</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    cyclic_lr: bool</span>
<span class="sd">        Attribute that indicates if any of the lr_schedulers is cyclic_lr</span>
<span class="sd">        (i.e. `CyclicLR` or</span>
<span class="sd">        `OneCycleLR`). See [Pytorch schedulers](https://pytorch.org/docs/stable/optim.html).</span>
<span class="sd">    feature_importance: dict</span>
<span class="sd">        dict where the keys are the column names and the values are the</span>
<span class="sd">        corresponding feature importances. This attribute will only exist</span>
<span class="sd">        if the `deeptabular` component is a Tabnet model.</span>

<span class="sd">    Examples</span>
<span class="sd">    --------</span>
<span class="sd">    &gt;&gt;&gt; import torch</span>
<span class="sd">    &gt;&gt;&gt; from torchvision.transforms import ToTensor</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; # wide deep imports</span>
<span class="sd">    &gt;&gt;&gt; from pytorch_widedeep.callbacks import EarlyStopping, LRHistory</span>
<span class="sd">    &gt;&gt;&gt; from pytorch_widedeep.initializers import KaimingNormal, KaimingUniform, Normal, Uniform</span>
<span class="sd">    &gt;&gt;&gt; from pytorch_widedeep.models import TabResnet, Vision, BasicRNN, Wide, WideDeep</span>
<span class="sd">    &gt;&gt;&gt; from pytorch_widedeep import Trainer</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; embed_input = [(u, i, j) for u, i, j in zip([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;][:4], [4] * 3, [8] * 3)]</span>
<span class="sd">    &gt;&gt;&gt; column_idx = {k: v for v, k in enumerate([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;])}</span>
<span class="sd">    &gt;&gt;&gt; wide = Wide(10, 1)</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; # build the model</span>
<span class="sd">    &gt;&gt;&gt; deeptabular = TabResnet(blocks_dims=[8, 4], column_idx=column_idx, cat_embed_input=embed_input)</span>
<span class="sd">    &gt;&gt;&gt; deeptext = BasicRNN(vocab_size=10, embed_dim=4, padding_idx=0)</span>
<span class="sd">    &gt;&gt;&gt; deepimage = Vision()</span>
<span class="sd">    &gt;&gt;&gt; model = WideDeep(wide=wide, deeptabular=deeptabular, deeptext=deeptext, deepimage=deepimage)</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; # set optimizers and schedulers</span>
<span class="sd">    &gt;&gt;&gt; wide_opt = torch.optim.Adam(model.wide.parameters())</span>
<span class="sd">    &gt;&gt;&gt; deep_opt = torch.optim.AdamW(model.deeptabular.parameters())</span>
<span class="sd">    &gt;&gt;&gt; text_opt = torch.optim.Adam(model.deeptext.parameters())</span>
<span class="sd">    &gt;&gt;&gt; img_opt = torch.optim.AdamW(model.deepimage.parameters())</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; wide_sch = torch.optim.lr_scheduler.StepLR(wide_opt, step_size=5)</span>
<span class="sd">    &gt;&gt;&gt; deep_sch = torch.optim.lr_scheduler.StepLR(deep_opt, step_size=3)</span>
<span class="sd">    &gt;&gt;&gt; text_sch = torch.optim.lr_scheduler.StepLR(text_opt, step_size=5)</span>
<span class="sd">    &gt;&gt;&gt; img_sch = torch.optim.lr_scheduler.StepLR(img_opt, step_size=3)</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; optimizers = {&quot;wide&quot;: wide_opt, &quot;deeptabular&quot;: deep_opt, &quot;deeptext&quot;: text_opt, &quot;deepimage&quot;: img_opt}</span>
<span class="sd">    &gt;&gt;&gt; schedulers = {&quot;wide&quot;: wide_sch, &quot;deeptabular&quot;: deep_sch, &quot;deeptext&quot;: text_sch, &quot;deepimage&quot;: img_sch}</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; # set initializers and callbacks</span>
<span class="sd">    &gt;&gt;&gt; initializers = {&quot;wide&quot;: Uniform, &quot;deeptabular&quot;: Normal, &quot;deeptext&quot;: KaimingNormal, &quot;deepimage&quot;: KaimingUniform}</span>
<span class="sd">    &gt;&gt;&gt; transforms = [ToTensor]</span>
<span class="sd">    &gt;&gt;&gt; callbacks = [LRHistory(n_epochs=4), EarlyStopping]</span>
<span class="sd">    &gt;&gt;&gt;</span>
<span class="sd">    &gt;&gt;&gt; # set the trainer</span>
<span class="sd">    &gt;&gt;&gt; trainer = Trainer(model, objective=&quot;regression&quot;, initializers=initializers, optimizers=optimizers,</span>
<span class="sd">    ... lr_schedulers=schedulers, callbacks=callbacks, transforms=transforms)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@alias</span><span class="p">(</span>  <span class="c1"># noqa: C901</span>
        <span class="s2">&quot;objective&quot;</span><span class="p">,</span>
        <span class="p">[</span><span class="s2">&quot;loss_function&quot;</span><span class="p">,</span> <span class="s2">&quot;loss_fn&quot;</span><span class="p">,</span> <span class="s2">&quot;loss&quot;</span><span class="p">,</span> <span class="s2">&quot;cost_function&quot;</span><span class="p">,</span> <span class="s2">&quot;cost_fn&quot;</span><span class="p">,</span> <span class="s2">&quot;cost&quot;</span><span class="p">],</span>
    <span class="p">)</span>
    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;metrics&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;train_metrics&quot;</span><span class="p">])</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">model</span><span class="p">:</span> <span class="n">WideDeep</span><span class="p">,</span>
        <span class="n">objective</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
        <span class="n">custom_loss_function</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">optimizers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span>
            <span class="n">Union</span><span class="p">[</span><span class="n">Optimizer</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Optimizer</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Optimizer</span><span class="p">]]]]</span>
        <span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">lr_schedulers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span>
            <span class="n">Union</span><span class="p">[</span><span class="n">LRScheduler</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">LRScheduler</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">LRScheduler</span><span class="p">]]]]</span>
        <span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">initializers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span>
            <span class="n">Union</span><span class="p">[</span><span class="n">Initializer</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Initializer</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Initializer</span><span class="p">]]]]</span>
        <span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">transforms</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Transforms</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">callbacks</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Callback</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">metrics</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Metric</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">TorchMetric</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">eval_metrics</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">Metric</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">TorchMetric</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">verbose</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
        <span class="n">seed</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
        <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">,</span>
            <span class="n">objective</span><span class="o">=</span><span class="n">objective</span><span class="p">,</span>
            <span class="n">custom_loss_function</span><span class="o">=</span><span class="n">custom_loss_function</span><span class="p">,</span>
            <span class="n">optimizers</span><span class="o">=</span><span class="n">optimizers</span><span class="p">,</span>
            <span class="n">lr_schedulers</span><span class="o">=</span><span class="n">lr_schedulers</span><span class="p">,</span>
            <span class="n">initializers</span><span class="o">=</span><span class="n">initializers</span><span class="p">,</span>
            <span class="n">transforms</span><span class="o">=</span><span class="n">transforms</span><span class="p">,</span>
            <span class="n">callbacks</span><span class="o">=</span><span class="n">callbacks</span><span class="p">,</span>
            <span class="n">metrics</span><span class="o">=</span><span class="n">metrics</span><span class="p">,</span>
            <span class="n">eval_metrics</span><span class="o">=</span><span class="n">eval_metrics</span><span class="p">,</span>
            <span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">,</span>
            <span class="n">seed</span><span class="o">=</span><span class="n">seed</span><span class="p">,</span>
            <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
        <span class="p">)</span>

    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;finetune&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;warmup&quot;</span><span class="p">])</span>
    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;train_dataloader&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;custom_dataloader&quot;</span><span class="p">])</span>
    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;eval_dataloader&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;custom_eval_dataloader&quot;</span><span class="p">])</span>
    <span class="k">def</span> <span class="nf">fit</span><span class="p">(</span>  <span class="c1"># noqa: C901</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_train</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_val</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">val_split</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">target</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">n_epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
        <span class="n">validation_freq</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">32</span><span class="p">,</span>
        <span class="n">train_dataloader</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CustomDataLoader</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">eval_dataloader</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CustomDataLoader</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">feature_importance_sample_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">finetune</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
    <span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Fit method.</span>

<span class="sd">        The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">        (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">        dictionaries (`X_train` or `X_val`).</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `wide` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">        X_tab: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `deeptabular` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TabPreprocessor`. If multiple</span>
<span class="sd">            tabular models are used for different columns, this should be a</span>
<span class="sd">            list of numpy arrays</span>
<span class="sd">        X_text: Union[np.ndarray, List[np.ndarray]], Optional. default=None</span>
<span class="sd">            Input for the `deeptext` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TextPreprocessor`.</span>
<span class="sd">            If multiple text columns/models are used, this should be a list of</span>
<span class="sd">            numpy arrays</span>
<span class="sd">        X_img: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `deepimage` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.ImagePreprocessor`.</span>
<span class="sd">            If multiple image columns/models are used, this should be a list of</span>
<span class="sd">            numpy arrays</span>
<span class="sd">        X_train: Dict, Optional. default=None</span>
<span class="sd">            The training dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">            _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">            are the corresponding matrices. Note that of multiple text or image</span>
<span class="sd">            columns/models are used, the corresponding values should be lists</span>
<span class="sd">            of numpy arrays</span>
<span class="sd">        X_val: Dict, Optional. default=None</span>
<span class="sd">            The validation dataset can also be passed in a dictionary. Keys</span>
<span class="sd">            are _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_.</span>
<span class="sd">            Values are the corresponding matrices. Note that of multiple text</span>
<span class="sd">            or image columns/models are used, the corresponding values should</span>
<span class="sd">            be lists of numpy arrays</span>
<span class="sd">        val_split: float, Optional. default=None</span>
<span class="sd">            train/val split fraction</span>
<span class="sd">        target: np.ndarray, Optional. default=None</span>
<span class="sd">            target values</span>
<span class="sd">        n_epochs: int, default=1</span>
<span class="sd">            number of epochs</span>
<span class="sd">        validation_freq: int, default=1</span>
<span class="sd">            epochs validation frequency</span>
<span class="sd">        batch_size: int, default=32</span>
<span class="sd">            batch size</span>
<span class="sd">        custom_dataloader: `DataLoader`, Optional, default=None</span>
<span class="sd">            object of class `torch.utils.data.DataLoader`. Available</span>
<span class="sd">            predefined dataloaders are in `pytorch-widedeep.dataloaders`.If</span>
<span class="sd">            `None`, a standard torch `DataLoader` is used.</span>
<span class="sd">        finetune: bool, default=False</span>
<span class="sd">            fine-tune individual model components. This functionality can also</span>
<span class="sd">            be used to &#39;warm-up&#39; (and hence the alias `warmup`) individual</span>
<span class="sd">            components before the joined training starts, and hence its</span>
<span class="sd">            alias. See the Examples folder in the repo for more details</span>

<span class="sd">            `pytorch_widedeep` implements 3 fine-tune routines.</span>

<span class="sd">            - fine-tune all trainable layers at once. This routine is</span>
<span class="sd">              inspired by the work of Howard &amp; Sebastian Ruder 2018 in their</span>
<span class="sd">              [ULMfit paper](https://arxiv.org/abs/1801.06146). Using a</span>
<span class="sd">              Slanted Triangular learing (see</span>
<span class="sd">              [Leslie N. Smith paper](https://arxiv.org/pdf/1506.01186.pdf) ) ,</span>
<span class="sd">              the process is the following: *i*) the learning rate will</span>
<span class="sd">              gradually increase for 10% of the training steps from max_lr/10</span>
<span class="sd">              to max_lr. *ii*) It will then gradually decrease to max_lr/10</span>
<span class="sd">              for the remaining 90% of the steps. The optimizer used in the</span>
<span class="sd">              process is `Adam`.</span>

<span class="sd">            and two gradual fine-tune routines, where only certain layers are</span>
<span class="sd">            trained at a time.</span>

<span class="sd">            - The so called `Felbo` gradual fine-tune rourine, based on the the</span>
<span class="sd">              Felbo et al., 2017 [DeepEmoji paper](https://arxiv.org/abs/1708.00524).</span>
<span class="sd">            - The `Howard` routine based on the work of Howard &amp; Sebastian Ruder 2018 in their</span>
<span class="sd">              [ULMfit paper](https://arxiv.org/abs/1801.06146&gt;).</span>

<span class="sd">            For details on how these routines work, please see the Examples</span>
<span class="sd">            section in this documentation and the Examples folder in the repo. &lt;br/&gt;</span>
<span class="sd">            Param Alias: `warmup`</span>

<span class="sd">        Other Parameters</span>
<span class="sd">        ----------------</span>
<span class="sd">        **kwargs:</span>
<span class="sd">            Other keyword arguments are:</span>

<span class="sd">            - **DataLoader related parameters**:&lt;br/&gt;</span>
<span class="sd">                For example,  `sampler`, `batch_sampler`, `collate_fn`, etc.</span>
<span class="sd">                Please, see the pytorch</span>
<span class="sd">                [DataLoader docs](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader)</span>
<span class="sd">                for details.</span>

<span class="sd">            - **Finetune related parameters**:&lt;br/&gt;</span>
<span class="sd">                see the source code at `pytorch_widedeep._finetune`. Namely, these are:</span>

<span class="sd">                - `finetune_epochs` (`int`):</span>
<span class="sd">                    number of epochs use for fine tuning</span>
<span class="sd">                - `finetune_max_lr` (`float`):</span>
<span class="sd">                   max lr during fine tuning</span>
<span class="sd">                - `routine` (`str`):</span>
<span class="sd">                   one of _&#39;howard&#39;_ or _&#39;felbo&#39;_</span>
<span class="sd">                - `deeptabular_gradual` (`bool`):</span>
<span class="sd">                   boolean indicating if the `deeptabular` component will be fine tuned gradually</span>
<span class="sd">                - `deeptabular_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">                   List of pytorch modules indicating the layers of the</span>
<span class="sd">                   `deeptabular` that will be fine tuned</span>
<span class="sd">                - `deeptabular_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">                   max lr for the `deeptabular` componet during fine tuning</span>
<span class="sd">                - `deeptext_gradual` (`bool`):</span>
<span class="sd">                   same as `deeptabular_gradual` but for the `deeptext` component</span>
<span class="sd">                - `deeptext_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">                   same as `deeptabular_gradual` but for the `deeptext` component.</span>
<span class="sd">                   If there are multiple text columns/models, this should be a list of lists</span>
<span class="sd">                - `deeptext_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">                   same as `deeptabular_gradual` but for the `deeptext` component</span>
<span class="sd">                   If there are multiple text columns/models, this should be a list of floats</span>
<span class="sd">                - `deepimage_gradual` (`bool`):</span>
<span class="sd">                   same as `deeptext_layers` but for the `deepimage` component</span>
<span class="sd">                - `deepimage_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">                   same as `deeptext_layers` but for the `deepimage` component</span>
<span class="sd">                - `deepimage_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">                    same as `deeptext_layers` but for the `deepimage` component</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>

<span class="sd">        For a series of comprehensive examples on how to use the `fit` method, please see the</span>
<span class="sd">        [Examples](https://github.com/jrzaurin/pytorch-widedeep/tree/master/examples)</span>
<span class="sd">        folder in the repo</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dataloader_args</span><span class="p">,</span> <span class="n">finetune_args</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extract_kwargs</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">batch_size</span>
        <span class="n">train_set</span><span class="p">,</span> <span class="n">eval_set</span> <span class="o">=</span> <span class="n">wd_train_val_split</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">seed</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">,</span>  <span class="c1"># type: ignore</span>
            <span class="n">X_wide</span><span class="p">,</span>
            <span class="n">X_tab</span><span class="p">,</span>
            <span class="n">X_text</span><span class="p">,</span>
            <span class="n">X_img</span><span class="p">,</span>
            <span class="n">X_train</span><span class="p">,</span>
            <span class="n">X_val</span><span class="p">,</span>
            <span class="n">val_split</span><span class="p">,</span>
            <span class="n">target</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">train_loader</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_dataloader</span><span class="p">(</span>
            <span class="n">train_dataloader</span><span class="p">,</span> <span class="n">train_set</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">dataloader_args</span>
        <span class="p">)</span>
        <span class="n">eval_loader</span> <span class="o">=</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_dataloader</span><span class="p">(</span><span class="n">eval_dataloader</span><span class="p">,</span> <span class="n">eval_set</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">dataloader_args</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">eval_set</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
            <span class="k">else</span> <span class="kc">None</span>
        <span class="p">)</span>

        <span class="k">if</span> <span class="n">finetune</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">with_finetuning</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_do_finetune</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="o">**</span><span class="n">finetune_args</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span>
                    <span class="s2">&quot;Fine-tuning (or warmup) of individual components completed. &quot;</span>
                    <span class="s2">&quot;Training the whole model for </span><span class="si">{}</span><span class="s2"> epochs&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">n_epochs</span><span class="p">)</span>
                <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">with_finetuning</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_train_begin</span><span class="p">(</span>
            <span class="p">{</span>
                <span class="s2">&quot;batch_size&quot;</span><span class="p">:</span> <span class="n">batch_size</span><span class="p">,</span>
                <span class="s2">&quot;train_steps&quot;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">train_loader</span><span class="p">),</span>
                <span class="s2">&quot;n_epochs&quot;</span><span class="p">:</span> <span class="n">n_epochs</span><span class="p">,</span>
            <span class="p">}</span>
        <span class="p">)</span>
        <span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_epochs</span><span class="p">):</span>
            <span class="n">epoch_logs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_train_epoch</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">eval_loader</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">epoch</span> <span class="o">%</span> <span class="n">validation_freq</span> <span class="o">==</span> <span class="p">(</span>
                <span class="n">validation_freq</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="p">):</span>
                <span class="n">epoch_logs</span><span class="p">,</span> <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_eval_epoch</span><span class="p">(</span>
                    <span class="n">eval_loader</span><span class="p">,</span> <span class="n">epoch_logs</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reducelronplateau</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span>
                        <span class="s2">&quot;ReduceLROnPlateau scheduler can be used only with validation data.&quot;</span>
                    <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_epoch_end</span><span class="p">(</span><span class="n">epoch</span><span class="p">,</span> <span class="n">epoch_logs</span><span class="p">,</span> <span class="n">on_epoch_end_metric</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span><span class="p">:</span>
                <span class="c1"># self.callback_container.on_train_end(epoch_logs)</span>
                <span class="k">break</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_train_end</span><span class="p">(</span><span class="n">epoch_logs</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">feature_importance_sample_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance</span> <span class="o">=</span> <span class="n">FeatureImportance</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">,</span> <span class="n">feature_importance_sample_size</span>
            <span class="p">)</span><span class="o">.</span><span class="n">feature_importance</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_restore_best_weights</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span>  <span class="c1"># type: ignore[override, return]</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predictions</span>

<span class="sd">        The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">        (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">        a dictionary (`X_test`)</span>


<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `wide` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">        X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptabular` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">        X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptext` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">        X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deepimage` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">        X_test: Dict, Optional. default=None</span>
<span class="sd">            The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">            `X_wide`, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">            are the corresponding matrices.</span>
<span class="sd">        batch_size: int, default = 256</span>
<span class="sd">            If a trainer is used to predict after having trained a model, the</span>
<span class="sd">            `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">            the `Trainer` is instantiated</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        np.ndarray:</span>
<span class="sd">            array with the predictions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span><span class="n">X_wide</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">,</span> <span class="n">X_text</span><span class="p">,</span> <span class="n">X_img</span><span class="p">,</span> <span class="n">X_test</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="k">return</span> <span class="p">(</span><span class="n">preds</span> <span class="o">&gt;</span> <span class="mf">0.5</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s2">&quot;int&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;qregression&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">preds</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>  <span class="c1"># type: ignore[return-value]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">in</span> <span class="p">[</span>
                <span class="s2">&quot;MultiTargetClassificationLoss&quot;</span><span class="p">,</span>
                <span class="s2">&quot;MutilTargetRegressionAndClassificationLoss&quot;</span><span class="p">,</span>
            <span class="p">]:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;MultiTargetClassificationLoss and MutilTargetRegressionAndClassificationLoss &quot;</span>
                    <span class="s2">&quot;are not supported by predict method. Please use predict_proba method instead.&quot;</span>
                <span class="p">)</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">predict_uncertainty</span><span class="p">(</span>  <span class="c1"># type: ignore[return]</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">uncertainty_granularity</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">,</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predicted ucnertainty of the model for the test dataset</span>
<span class="sd">        using a Monte Carlo method during which dropout layers are activated</span>
<span class="sd">        in the evaluation/prediction phase and each sample is predicted N</span>
<span class="sd">        times (`uncertainty_granularity` times).</span>

<span class="sd">        This is based on</span>
<span class="sd">        [Dropout as a Bayesian Approximation: Representing</span>
<span class="sd">        Model Uncertainty in Deep Learning](https://arxiv.org/abs/1506.02142?context=stat).</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `wide` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">        X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptabular` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">        X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptext` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">        X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deepimage` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">        X_test: Dict, Optional. default=None</span>
<span class="sd">            The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">            _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">            are the corresponding matrices.</span>
<span class="sd">        batch_size: int, default = 256</span>
<span class="sd">            If a trainer is used to predict after having trained a model, the</span>
<span class="sd">            `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">            the `Trainer` is instantiated</span>
<span class="sd">        uncertainty_granularity: int default = 1000</span>
<span class="sd">            number of times the model does prediction for each sample</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        np.ndarray:</span>
<span class="sd">            - if `method = regression`, it will return an array with `(max, min, mean, stdev)`</span>
<span class="sd">              values for each sample.</span>
<span class="sd">            - if `method = binary` it will return an array with</span>
<span class="sd">              `(mean_cls_0_prob, mean_cls_1_prob, predicted_cls)` for each sample.</span>
<span class="sd">            - if `method = multiclass` it will return an array with</span>
<span class="sd">              `(mean_cls_0_prob, mean_cls_1_prob, mean_cls_2_prob, ... , predicted_cls)`</span>
<span class="sd">              values for each sample.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span>
            <span class="n">X_wide</span><span class="p">,</span>
            <span class="n">X_tab</span><span class="p">,</span>
            <span class="n">X_text</span><span class="p">,</span>
            <span class="n">X_img</span><span class="p">,</span>
            <span class="n">X_test</span><span class="p">,</span>
            <span class="n">batch_size</span><span class="p">,</span>
            <span class="n">uncertainty_granularity</span><span class="p">,</span>
            <span class="n">uncertainty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
        <span class="n">samples_num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">uncertainty_granularity</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
                <span class="p">(</span>
                    <span class="n">preds</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                    <span class="n">preds</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                    <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                    <span class="n">preds</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                <span class="p">)</span>
            <span class="p">)</span><span class="o">.</span><span class="n">T</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;qregression&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Currently predict_uncertainty is not supported for qregression method&quot;</span>
            <span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">))</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">probs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">3</span><span class="p">])</span>
            <span class="n">probs</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">preds</span>
            <span class="n">probs</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">preds</span>
            <span class="k">return</span> <span class="n">probs</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">,</span> <span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">preds</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">preds</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
            <span class="k">return</span> <span class="n">preds</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Currently predict_uncertainty is not supported for multitarget method&quot;</span>
            <span class="p">)</span>

    <span class="k">def</span> <span class="nf">predict_proba</span><span class="p">(</span>  <span class="c1"># type: ignore[override, return]  # noqa: C901</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predicted probabilities for the test dataset for  binary</span>
<span class="sd">        and multiclass methods</span>

<span class="sd">        The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">        (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">        a dictionary (`X_test`)</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">            Input for the `wide` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">        X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptabular` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">        X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deeptext` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">        X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">            Input for the `deepimage` model component.</span>
<span class="sd">            See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">        X_test: Dict, Optional. default=None</span>
<span class="sd">            The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">            `X_wide`, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">            are the corresponding matrices.</span>
<span class="sd">        batch_size: int, default = 256</span>
<span class="sd">            If a trainer is used to predict after having trained a model, the</span>
<span class="sd">            `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">            the `Trainer` is instantiated</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        np.ndarray</span>
<span class="sd">            array with the probabilities per class</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span><span class="n">X_wide</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">,</span> <span class="n">X_text</span><span class="p">,</span> <span class="n">X_img</span><span class="p">,</span> <span class="n">X_test</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
            <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">probs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">2</span><span class="p">])</span>
            <span class="n">probs</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">preds</span>
            <span class="n">probs</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">preds</span>
            <span class="k">return</span> <span class="n">probs</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">explain</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">save_step_masks</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
        <span class="c1"># TO DO: Add docs to this, to the feat imp parameter and the all</span>
        <span class="c1"># related classes</span>
        <span class="n">explainer</span> <span class="o">=</span> <span class="n">Explainer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>

        <span class="n">res</span> <span class="o">=</span> <span class="n">explainer</span><span class="o">.</span><span class="n">explain</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">save_step_masks</span>
        <span class="p">)</span>

        <span class="k">return</span> <span class="n">res</span>

    <span class="k">def</span> <span class="nf">save</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
        <span class="n">save_state_dict</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="n">save_optimizer</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="n">model_filename</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;wd_model.pt&quot;</span><span class="p">,</span>
    <span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Saves the model, training and evaluation history, and the</span>
<span class="sd">        `feature_importance` attribute (if the `deeptabular` component is a</span>
<span class="sd">        Tabnet model) to disk</span>

<span class="sd">        The `Trainer` class is built so that it &#39;just&#39; trains a model. With</span>
<span class="sd">        that in mind, all the torch related parameters (such as optimizers,</span>
<span class="sd">        learning rate schedulers, initializers, etc) have to be defined</span>
<span class="sd">        externally and then passed to the `Trainer`. As a result, the</span>
<span class="sd">        `Trainer` does not generate any attribute or additional data</span>
<span class="sd">        products that need to be saved other than the `model` object itself,</span>
<span class="sd">        which can be saved as any other torch model (e.g. `torch.save(model,</span>
<span class="sd">        path)`).</span>

<span class="sd">        The exception is Tabnet. If the `deeptabular` component is a Tabnet</span>
<span class="sd">        model, an attribute (a dict) called `feature_importance` will be</span>
<span class="sd">        created at the end of the training process. Therefore, a `save`</span>
<span class="sd">        method was created that will save the feature importance dictionary</span>
<span class="sd">        to a json file and, since we are here, the model weights, training</span>
<span class="sd">        history and learning rate history.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        path: str</span>
<span class="sd">            path to the directory where the model and the feature importance</span>
<span class="sd">            attribute will be saved.</span>
<span class="sd">        save_state_dict: bool, default = False</span>
<span class="sd">            Boolean indicating whether to save directly the model</span>
<span class="sd">            (and optimizer) or the model&#39;s (and optimizer&#39;s) state</span>
<span class="sd">            dictionary</span>
<span class="sd">        save_optimizer: bool, default = False</span>
<span class="sd">            Boolean indicating whether to save the optimizer</span>
<span class="sd">        model_filename: str, Optional, default = &quot;wd_model.pt&quot;</span>
<span class="sd">            filename where the model weights will be store</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_save_history</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_save_model_and_optimizer</span><span class="p">(</span>
            <span class="n">path</span><span class="p">,</span> <span class="n">save_state_dict</span><span class="p">,</span> <span class="n">save_optimizer</span><span class="p">,</span> <span class="n">model_filename</span>
        <span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_tabnet</span><span class="p">:</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="o">/</span> <span class="s2">&quot;feature_importance.json&quot;</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fi</span><span class="p">:</span>
                <span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_importance</span><span class="p">,</span> <span class="n">fi</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_dataloader</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">dataloader</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CustomDataLoader</span><span class="p">],</span>
        <span class="n">dataset</span><span class="p">:</span> <span class="n">WideDeepDataset</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
        <span class="n">dataloader_args</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">],</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Union</span><span class="p">[</span><span class="n">DataLoader</span><span class="p">,</span> <span class="n">CustomDataLoader</span><span class="p">]:</span>
        <span class="k">if</span> <span class="n">dataloader</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">dataloader</span><span class="o">.</span><span class="n">set_dataset</span><span class="p">(</span><span class="n">dataset</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">dataloader</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># var name &#39;loader&#39; to avoid reassigment and type errors</span>
            <span class="n">loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span>
                <span class="n">dataset</span><span class="o">=</span><span class="n">dataset</span><span class="p">,</span>
                <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span>
                <span class="n">num_workers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">,</span>
                <span class="o">**</span><span class="n">dataloader_args</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="k">return</span> <span class="n">loader</span>

    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;n_epochs&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;finetune_epochs&quot;</span><span class="p">,</span> <span class="s2">&quot;warmup_epochs&quot;</span><span class="p">])</span>
    <span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;max_lr&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;finetune_max_lr&quot;</span><span class="p">,</span> <span class="s2">&quot;warmup_max_lr&quot;</span><span class="p">])</span>
    <span class="k">def</span> <span class="nf">_do_finetune</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">loader</span><span class="p">:</span> <span class="n">DataLoader</span><span class="p">,</span>
        <span class="n">n_epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">5</span><span class="p">,</span>
        <span class="n">max_lr</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span>
        <span class="n">routine</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;howard&quot;</span><span class="p">,</span> <span class="s2">&quot;felbo&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;howard&quot;</span><span class="p">,</span>
        <span class="n">deeptabular_gradual</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="n">deeptabular_layers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span>
            <span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">]]]</span>
        <span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">deeptabular_max_lr</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="nb">float</span><span class="p">]]</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span>
        <span class="n">deeptext_gradual</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="n">deeptext_layers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">deeptext_max_lr</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="nb">float</span><span class="p">]]</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span>
        <span class="n">deepimage_gradual</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
        <span class="n">deepimage_layers</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span>
            <span class="n">Union</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">],</span> <span class="n">List</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">]]]</span>
        <span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">deepimage_max_lr</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="nb">float</span><span class="p">]]</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span>
    <span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Simple wrap-up to individually fine-tune model components</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deephead</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Currently warming up is only supported without a fully connected &#39;DeepHead&#39;&quot;</span>
            <span class="p">)</span>

        <span class="n">finetuner</span> <span class="o">=</span> <span class="n">FineTune</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">)</span>  <span class="c1"># type: ignore[arg-type]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">wide</span><span class="p">:</span>
            <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">wide</span><span class="p">,</span> <span class="s2">&quot;wide&quot;</span><span class="p">,</span> <span class="n">loader</span><span class="p">,</span> <span class="n">n_epochs</span><span class="p">,</span> <span class="n">max_lr</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptabular</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">deeptabular_gradual</span><span class="p">:</span>
                <span class="k">assert</span> <span class="p">(</span>
                    <span class="n">deeptabular_layers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                <span class="p">),</span> <span class="s2">&quot;deeptabular_layers must be passed if deeptabular_gradual=True&quot;</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_gradual</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptabular</span><span class="p">,</span>
                    <span class="s2">&quot;deeptabular&quot;</span><span class="p">,</span>
                    <span class="n">loader</span><span class="p">,</span>
                    <span class="n">deeptabular_max_lr</span><span class="p">,</span>
                    <span class="n">deeptabular_layers</span><span class="p">,</span>
                    <span class="n">routine</span><span class="p">,</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_all</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptabular</span><span class="p">,</span> <span class="s2">&quot;deeptabular&quot;</span><span class="p">,</span> <span class="n">loader</span><span class="p">,</span> <span class="n">n_epochs</span><span class="p">,</span> <span class="n">max_lr</span>
                <span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptext</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">deeptext_gradual</span><span class="p">:</span>
                <span class="k">assert</span> <span class="p">(</span>
                    <span class="n">deeptext_layers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                <span class="p">),</span> <span class="s2">&quot;deeptext_layers must be passed if deeptext_gradual=True&quot;</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_gradual</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptext</span><span class="p">,</span>
                    <span class="s2">&quot;deeptext&quot;</span><span class="p">,</span>
                    <span class="n">loader</span><span class="p">,</span>
                    <span class="n">deeptext_max_lr</span><span class="p">,</span>
                    <span class="n">deeptext_layers</span><span class="p">,</span>
                    <span class="n">routine</span><span class="p">,</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_all</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deeptext</span><span class="p">,</span> <span class="s2">&quot;deeptext&quot;</span><span class="p">,</span> <span class="n">loader</span><span class="p">,</span> <span class="n">n_epochs</span><span class="p">,</span> <span class="n">max_lr</span>
                <span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deepimage</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">deepimage_gradual</span><span class="p">:</span>
                <span class="k">assert</span> <span class="p">(</span>
                    <span class="n">deepimage_layers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                <span class="p">),</span> <span class="s2">&quot;deepimage_layers must be passed if deepimage_gradual=True&quot;</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_gradual</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deepimage</span><span class="p">,</span>
                    <span class="s2">&quot;deepimage&quot;</span><span class="p">,</span>
                    <span class="n">loader</span><span class="p">,</span>
                    <span class="n">deepimage_max_lr</span><span class="p">,</span>
                    <span class="n">deepimage_layers</span><span class="p">,</span>
                    <span class="n">routine</span><span class="p">,</span>
                <span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">finetuner</span><span class="o">.</span><span class="n">finetune_all</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">deepimage</span><span class="p">,</span> <span class="s2">&quot;deepimage&quot;</span><span class="p">,</span> <span class="n">loader</span><span class="p">,</span> <span class="n">n_epochs</span><span class="p">,</span> <span class="n">max_lr</span>
                <span class="p">)</span>

    <span class="k">def</span> <span class="nf">_train_epoch</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">train_loader</span><span class="p">:</span> <span class="n">DataLoader</span><span class="p">,</span>
        <span class="n">epoch</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="n">epoch_logs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_epoch_begin</span><span class="p">(</span><span class="n">epoch</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="n">epoch_logs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">train_running_loss</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="n">train_steps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">train_loader</span><span class="p">)</span>
        <span class="k">with</span> <span class="n">trange</span><span class="p">(</span><span class="n">train_steps</span><span class="p">,</span> <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">batch_idx</span><span class="p">,</span> <span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">targett</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">train_loader</span><span class="p">):</span>
                <span class="n">t</span><span class="o">.</span><span class="n">set_description</span><span class="p">(</span><span class="s2">&quot;epoch </span><span class="si">%i</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">epoch</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
                <span class="n">train_score</span><span class="p">,</span> <span class="n">train_loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_train_step</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">targett</span><span class="p">,</span> <span class="n">batch_idx</span><span class="p">)</span>
                <span class="n">print_loss_and_metric</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">train_loss</span><span class="p">,</span> <span class="n">train_score</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_batch_end</span><span class="p">(</span><span class="n">batch</span><span class="o">=</span><span class="n">batch_idx</span><span class="p">)</span>

        <span class="n">epoch_logs</span> <span class="o">=</span> <span class="n">save_epoch_logs</span><span class="p">(</span><span class="n">epoch_logs</span><span class="p">,</span> <span class="n">train_loss</span><span class="p">,</span> <span class="n">train_score</span><span class="p">,</span> <span class="s2">&quot;train&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">epoch_logs</span>

    <span class="k">def</span> <span class="nf">_train_step</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">data</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Tensor</span><span class="p">]]],</span>
        <span class="n">target</span><span class="p">:</span> <span class="n">Tensor</span><span class="p">,</span>
        <span class="n">batch_idx</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
    <span class="p">):</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>

        <span class="n">X</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Tensor</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_device</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">to_device</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="p">(</span>
            <span class="n">target</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">float</span><span class="p">()</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;multiclass&quot;</span><span class="p">,</span> <span class="s2">&quot;qregression&quot;</span><span class="p">,</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">]</span>
            <span class="k">else</span> <span class="n">target</span>
        <span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">to_device</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">zero_grad</span><span class="p">()</span>

        <span class="n">y_pred</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_tabnet</span><span class="p">:</span>
            <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">(</span><span class="n">y_pred</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lambda_sparse</span> <span class="o">*</span> <span class="n">y_pred</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">score</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_score</span><span class="p">(</span><span class="n">y_pred</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">,</span> <span class="n">is_train</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
            <span class="n">score</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_score</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">is_train</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">optimizer</span><span class="o">.</span><span class="n">step</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">train_running_loss</span> <span class="o">+=</span> <span class="n">loss</span><span class="o">.</span><span class="n">item</span><span class="p">()</span>
        <span class="n">avg_loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">train_running_loss</span> <span class="o">/</span> <span class="p">(</span><span class="n">batch_idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">score</span><span class="p">,</span> <span class="n">avg_loss</span>

    <span class="k">def</span> <span class="nf">_eval_epoch</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">eval_loader</span><span class="p">:</span> <span class="n">DataLoader</span><span class="p">,</span>
        <span class="n">epoch_logs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">],</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">],</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]]:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_eval_begin</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valid_running_loss</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="n">eval_steps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">eval_loader</span><span class="p">)</span>
        <span class="k">with</span> <span class="n">trange</span><span class="p">(</span><span class="n">eval_steps</span><span class="p">,</span> <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">)</span> <span class="k">as</span> <span class="n">v</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">targett</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">eval_loader</span><span class="p">):</span>
                <span class="n">v</span><span class="o">.</span><span class="n">set_description</span><span class="p">(</span><span class="s2">&quot;valid&quot;</span><span class="p">)</span>
                <span class="n">val_score</span><span class="p">,</span> <span class="n">val_loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_eval_step</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">targett</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
                <span class="n">print_loss_and_metric</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">val_loss</span><span class="p">,</span> <span class="n">val_score</span><span class="p">)</span>

        <span class="n">epoch_logs</span> <span class="o">=</span> <span class="n">save_epoch_logs</span><span class="p">(</span><span class="n">epoch_logs</span><span class="p">,</span> <span class="n">val_loss</span><span class="p">,</span> <span class="n">val_score</span><span class="p">,</span> <span class="s2">&quot;val&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reducelronplateau</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reducelronplateau_criterion</span> <span class="o">==</span> <span class="s2">&quot;loss&quot;</span><span class="p">:</span>
                <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="n">val_loss</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="n">val_score</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">reducelronplateau_criterion</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">epoch_logs</span><span class="p">,</span> <span class="n">on_epoch_end_metric</span>

    <span class="k">def</span> <span class="nf">_eval_step</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">data</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Tensor</span><span class="p">]]],</span>
        <span class="n">target</span><span class="p">:</span> <span class="n">Tensor</span><span class="p">,</span>
        <span class="n">batch_idx</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
    <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span>
        <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span>
            <span class="n">X</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Tensor</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                    <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_device</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">to_device</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>
            <span class="n">y</span> <span class="o">=</span> <span class="p">(</span>
                <span class="n">target</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">float</span><span class="p">()</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;multiclass&quot;</span><span class="p">,</span> <span class="s2">&quot;qregression&quot;</span><span class="p">,</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">]</span>
                <span class="k">else</span> <span class="n">target</span>
            <span class="p">)</span>
            <span class="n">y</span> <span class="o">=</span> <span class="n">to_device</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>

            <span class="n">y_pred</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_tabnet</span><span class="p">:</span>
                <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">(</span><span class="n">y_pred</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">lambda_sparse</span> <span class="o">*</span> <span class="n">y_pred</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">score</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_score</span><span class="p">(</span><span class="n">y_pred</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span><span class="p">,</span> <span class="n">is_train</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">score</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_score</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">is_train</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">valid_running_loss</span> <span class="o">+=</span> <span class="n">loss</span><span class="o">.</span><span class="n">item</span><span class="p">()</span>
            <span class="n">avg_loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">valid_running_loss</span> <span class="o">/</span> <span class="p">(</span><span class="n">batch_idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">score</span><span class="p">,</span> <span class="n">avg_loss</span>

    <span class="k">def</span> <span class="nf">_get_score</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">:</span> <span class="n">Tensor</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">Tensor</span><span class="p">,</span> <span class="n">is_train</span><span class="p">:</span> <span class="nb">bool</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">]]:</span>

        <span class="n">score</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">metric</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_metric</span><span class="p">:</span>
            <span class="n">metric</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_metric</span><span class="p">:</span>
            <span class="n">metric</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span> <span class="k">if</span> <span class="n">is_train</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_metric</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">metric</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_metric</span><span class="p">:</span>
            <span class="n">metric</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="n">is_train</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_metric</span>

        <span class="k">if</span> <span class="n">metric</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span><span class="p">:</span>
                <span class="n">score</span> <span class="o">=</span> <span class="n">metric</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
                <span class="n">score</span> <span class="o">=</span> <span class="n">metric</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">sigmoid</span><span class="p">(</span><span class="n">y_pred</span><span class="p">),</span> <span class="n">y</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;qregression&quot;</span><span class="p">:</span>
                <span class="n">score</span> <span class="o">=</span> <span class="n">metric</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
                <span class="n">score</span> <span class="o">=</span> <span class="n">metric</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="n">y</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">score</span>

    <span class="k">def</span> <span class="nf">_predict</span><span class="p">(</span>  <span class="c1"># type: ignore[override, return]  # noqa: C901</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
        <span class="n">uncertainty_granularity</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">,</span>
        <span class="n">uncertainty</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">:</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Private method to avoid code repetition in predict and</span>
<span class="sd">        predict_proba. For parameter information, please, see the .predict()</span>
<span class="sd">        method documentation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">X_test</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">test_set</span> <span class="o">=</span> <span class="n">WideDeepDataset</span><span class="p">(</span><span class="o">**</span><span class="n">X_test</span><span class="p">)</span>  <span class="c1"># type: ignore[arg-type]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">load_dict</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">X_wide</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">load_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;X_wide&quot;</span><span class="p">:</span> <span class="n">X_wide</span><span class="p">}</span>
            <span class="k">if</span> <span class="n">X_tab</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">load_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;X_tab&quot;</span><span class="p">:</span> <span class="n">X_tab</span><span class="p">})</span>
            <span class="k">if</span> <span class="n">X_text</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">load_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;X_text&quot;</span><span class="p">:</span> <span class="n">X_text</span><span class="p">})</span>
            <span class="k">if</span> <span class="n">X_img</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">load_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;X_img&quot;</span><span class="p">:</span> <span class="n">X_img</span><span class="p">})</span>
            <span class="n">test_set</span> <span class="o">=</span> <span class="n">WideDeepDataset</span><span class="p">(</span><span class="o">**</span><span class="n">load_dict</span><span class="p">)</span>  <span class="c1"># type: ignore[arg-type]</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;batch_size&quot;</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">batch_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span> <span class="p">(</span>
                <span class="s2">&quot;&#39;batch_size&#39; has not be previosly set in this Trainer and must be&quot;</span>
                <span class="s2">&quot; specified via the &#39;batch_size&#39; argument in this predict call&quot;</span>
            <span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">batch_size</span>

        <span class="n">test_loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span>
            <span class="n">dataset</span><span class="o">=</span><span class="n">test_set</span><span class="p">,</span>
            <span class="n">batch_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span><span class="p">,</span>
            <span class="n">num_workers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">,</span>
            <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">test_steps</span> <span class="o">=</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">test_loader</span><span class="o">.</span><span class="n">dataset</span><span class="p">)</span> <span class="o">//</span> <span class="n">test_loader</span><span class="o">.</span><span class="n">batch_size</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>  <span class="c1"># type: ignore[arg-type]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">eval</span><span class="p">()</span>
        <span class="n">preds_l</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="n">uncertainty</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">modules</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">m</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;Dropout&quot;</span><span class="p">):</span>
                    <span class="n">m</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
            <span class="n">prediction_iters</span> <span class="o">=</span> <span class="n">uncertainty_granularity</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">prediction_iters</span> <span class="o">=</span> <span class="mi">1</span>

        <span class="k">with</span> <span class="n">torch</span><span class="o">.</span><span class="n">no_grad</span><span class="p">():</span>
            <span class="k">with</span> <span class="n">trange</span><span class="p">(</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">disable</span><span class="o">=</span><span class="n">uncertainty</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">)</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="n">prediction_iters</span><span class="p">)):</span>
                    <span class="n">t</span><span class="o">.</span><span class="n">set_description</span><span class="p">(</span><span class="s2">&quot;predict_UncertaintyIter&quot;</span><span class="p">)</span>

                    <span class="k">with</span> <span class="n">trange</span><span class="p">(</span>
                        <span class="n">test_steps</span><span class="p">,</span> <span class="n">disable</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">uncertainty</span> <span class="ow">is</span> <span class="kc">True</span>
                    <span class="p">)</span> <span class="k">as</span> <span class="n">tt</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">data</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">tt</span><span class="p">,</span> <span class="n">test_loader</span><span class="p">):</span>
                            <span class="n">tt</span><span class="o">.</span><span class="n">set_description</span><span class="p">(</span><span class="s2">&quot;predict&quot;</span><span class="p">)</span>
                            <span class="n">X</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">Tensor</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">{}</span>
                            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                                    <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_device</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="p">]</span>
                                <span class="k">else</span><span class="p">:</span>
                                    <span class="n">X</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">to_device</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">)</span>
                            <span class="n">preds</span> <span class="o">=</span> <span class="p">(</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
                                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_tabnet</span>
                                <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">(</span><span class="n">X</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                            <span class="p">)</span>
                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
                                <span class="n">preds</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">sigmoid</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span>
                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
                                <span class="n">preds</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">preds</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
                            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="p">,</span> <span class="n">ZILNLoss</span>
                            <span class="p">):</span>
                                <span class="n">preds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict_ziln</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span>
                            <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">cpu</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span>
                            <span class="n">preds_l</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">preds_l</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_predict_ziln</span><span class="p">(</span><span class="n">preds</span><span class="p">:</span> <span class="n">Tensor</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tensor</span><span class="p">:</span>
        <span class="c1"># Legacy implementation. It will be removed in future versions</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates predicted mean of zero inflated lognormal logits.</span>

<span class="sd">        Adjusted implementaion of `code</span>
<span class="sd">        &lt;https://github.com/google/lifetime_value/blob/master/lifetime_value/zero_inflated_lognormal.py&gt;`</span>

<span class="sd">        Arguments:</span>
<span class="sd">            preds: [batch_size, 3] tensor of logits.</span>
<span class="sd">        Returns:</span>
<span class="sd">            ziln_preds: [batch_size, 1] tensor of predicted mean.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">positive_probs</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">sigmoid</span><span class="p">(</span><span class="n">preds</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="p">:</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">loc</span> <span class="o">=</span> <span class="n">preds</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">softplus</span><span class="p">(</span><span class="n">preds</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="mi">2</span><span class="p">:])</span>
        <span class="n">ziln_preds</span> <span class="o">=</span> <span class="n">positive_probs</span> <span class="o">*</span> <span class="n">torch</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">loc</span> <span class="o">+</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">torch</span><span class="o">.</span><span class="n">square</span><span class="p">(</span><span class="n">scale</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">ziln_preds</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_extract_kwargs</span><span class="p">(</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">dataloader_params</span> <span class="o">=</span> <span class="p">[</span>
            <span class="s2">&quot;shuffle&quot;</span><span class="p">,</span>
            <span class="s2">&quot;sampler&quot;</span><span class="p">,</span>
            <span class="s2">&quot;batch_sampler&quot;</span><span class="p">,</span>
            <span class="s2">&quot;num_workers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;collate_fn&quot;</span><span class="p">,</span>
            <span class="s2">&quot;pin_memory&quot;</span><span class="p">,</span>
            <span class="s2">&quot;drop_last&quot;</span><span class="p">,</span>
            <span class="s2">&quot;timeout&quot;</span><span class="p">,</span>
            <span class="s2">&quot;worker_init_fn&quot;</span><span class="p">,</span>
            <span class="s2">&quot;generator&quot;</span><span class="p">,</span>
            <span class="s2">&quot;prefetch_factor&quot;</span><span class="p">,</span>
            <span class="s2">&quot;persistent_workers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;oversample_mul&quot;</span><span class="p">,</span>
        <span class="p">]</span>
        <span class="n">finetune_params</span> <span class="o">=</span> <span class="p">[</span>
            <span class="s2">&quot;n_epochs&quot;</span><span class="p">,</span>
            <span class="s2">&quot;finetune_epochs&quot;</span><span class="p">,</span>
            <span class="s2">&quot;warmup_epochs&quot;</span><span class="p">,</span>
            <span class="s2">&quot;max_lr&quot;</span><span class="p">,</span>
            <span class="s2">&quot;finetune_max_lr&quot;</span><span class="p">,</span>
            <span class="s2">&quot;warmup_max_lr&quot;</span><span class="p">,</span>
            <span class="s2">&quot;routine&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptabular_gradual&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptabular_layers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptabular_max_lr&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptext_gradual&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptext_layers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deeptext_max_lr&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deepimage_gradual&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deepimage_layers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;deepimage_max_lr&quot;</span><span class="p">,</span>
        <span class="p">]</span>

        <span class="n">dataloader_args</span><span class="p">,</span> <span class="n">finetune_args</span> <span class="o">=</span> <span class="p">{},</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">dataloader_params</span><span class="p">:</span>
                <span class="n">dataloader_args</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">finetune_params</span><span class="p">:</span>
                <span class="n">finetune_args</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>

        <span class="k">return</span> <span class="n">dataloader_args</span><span class="p">,</span> <span class="n">finetune_args</span>
</code></pre></div></td></tr></table></div>
              </details>



  <div class="doc doc-children">









<div class="doc doc-object doc-function">


<h3 id="pytorch_widedeep.training.Trainer.fit" class="doc doc-heading">
            <span class="doc doc-object-name doc-function-name">fit</span>


<a href="#pytorch_widedeep.training.Trainer.fit" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">fit</span><span class="p">(</span>
    <span class="n">X_wide</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_train</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_val</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">val_split</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">target</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">n_epochs</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
    <span class="n">validation_freq</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="o">=</span><span class="mi">32</span><span class="p">,</span>
    <span class="n">train_dataloader</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">eval_dataloader</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">feature_importance_sample_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">finetune</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
    <span class="o">**</span><span class="n">kwargs</span>
<span class="p">)</span>
</code></pre></div>

    <div class="doc doc-contents ">

        <p>Fit method.</p>
<p>The input datasets can be passed either directly via numpy arrays
(<code>X_wide</code>, <code>X_tab</code>, <code>X_text</code> or <code>X_img</code>) or alternatively, in
dictionaries (<code>X_train</code> or <code>X_val</code>).</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>X_wide</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="numpy.ndarray">ndarray</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>wide</code> model component.
See <code>pytorch_widedeep.preprocessing.WidePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_tab</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptabular</code> model component.
See <code>pytorch_widedeep.preprocessing.TabPreprocessor</code>. If multiple
tabular models are used for different columns, this should be a
list of numpy arrays</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_text</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptext</code> model component.
See <code>pytorch_widedeep.preprocessing.TextPreprocessor</code>.
If multiple text columns/models are used, this should be a list of
numpy arrays</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_img</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deepimage</code> model component.
See <code>pytorch_widedeep.preprocessing.ImagePreprocessor</code>.
If multiple image columns/models are used, this should be a list of
numpy arrays</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_train</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>The training dataset can also be passed in a dictionary. Keys are
<em>'X_wide'</em>, <em>'X_tab'</em>, <em>'X_text'</em>, <em>'X_img'</em> and <em>'target'</em>. Values
are the corresponding matrices. Note that of multiple text or image
columns/models are used, the corresponding values should be lists
of numpy arrays</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_val</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>The validation dataset can also be passed in a dictionary. Keys
are <em>'X_wide'</em>, <em>'X_tab'</em>, <em>'X_text'</em>, <em>'X_img'</em> and <em>'target'</em>.
Values are the corresponding matrices. Note that of multiple text
or image columns/models are used, the corresponding values should
be lists of numpy arrays</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>val_split</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[float]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>train/val split fraction</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>target</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="numpy.ndarray">ndarray</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>target values</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>n_epochs</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>number of epochs</p>
              </div>
            </td>
            <td>
                  <code>1</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>validation_freq</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>epochs validation frequency</p>
              </div>
            </td>
            <td>
                  <code>1</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>batch_size</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>batch size</p>
              </div>
            </td>
            <td>
                  <code>32</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>custom_dataloader</code>
            </td>
            <td>
            </td>
            <td>
              <div class="doc-md-description">
                <p>object of class <code>torch.utils.data.DataLoader</code>. Available
predefined dataloaders are in <code>pytorch-widedeep.dataloaders</code>.If
<code>None</code>, a standard torch <code>DataLoader</code> is used.</p>
              </div>
            </td>
            <td>
                <em>required</em>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>finetune</code>
            </td>
            <td>
                  <code>bool</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>fine-tune individual model components. This functionality can also
be used to 'warm-up' (and hence the alias <code>warmup</code>) individual
components before the joined training starts, and hence its
alias. See the Examples folder in the repo for more details</p>
<p><code>pytorch_widedeep</code> implements 3 fine-tune routines.</p>
<ul>
<li>fine-tune all trainable layers at once. This routine is
  inspired by the work of Howard &amp; Sebastian Ruder 2018 in their
  <a href="https://arxiv.org/abs/1801.06146">ULMfit paper</a>. Using a
  Slanted Triangular learing (see
  <a href="https://arxiv.org/pdf/1506.01186.pdf">Leslie N. Smith paper</a> ) ,
  the process is the following: <em>i</em>) the learning rate will
  gradually increase for 10% of the training steps from max_lr/10
  to max_lr. <em>ii</em>) It will then gradually decrease to max_lr/10
  for the remaining 90% of the steps. The optimizer used in the
  process is <code>Adam</code>.</li>
</ul>
<p>and two gradual fine-tune routines, where only certain layers are
trained at a time.</p>
<ul>
<li>The so called <code>Felbo</code> gradual fine-tune rourine, based on the the
  Felbo et al., 2017 <a href="https://arxiv.org/abs/1708.00524">DeepEmoji paper</a>.</li>
<li>The <code>Howard</code> routine based on the work of Howard &amp; Sebastian Ruder 2018 in their
  <a href="https://arxiv.org/abs/1801.06146&gt;">ULMfit paper</a>.</li>
</ul>
<p>For details on how these routines work, please see the Examples
section in this documentation and the Examples folder in the repo. <br/>
Param Alias: <code>warmup</code></p>
              </div>
            </td>
            <td>
                  <code>False</code>
            </td>
          </tr>
      </tbody>
    </table>


<p><span class="doc-section-title">Other Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td><code>**kwargs</code></td>
            <td>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Other keyword arguments are:</p>
<ul>
<li>
<p><strong>DataLoader related parameters</strong>:<br/>
    For example,  <code>sampler</code>, <code>batch_sampler</code>, <code>collate_fn</code>, etc.
    Please, see the pytorch
    <a href="https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader">DataLoader docs</a>
    for details.</p>
</li>
<li>
<p><strong>Finetune related parameters</strong>:<br/>
    see the source code at <code>pytorch_widedeep._finetune</code>. Namely, these are:</p>
<ul>
<li><code>finetune_epochs</code> (<code>int</code>):
    number of epochs use for fine tuning</li>
<li><code>finetune_max_lr</code> (<code>float</code>):
   max lr during fine tuning</li>
<li><code>routine</code> (<code>str</code>):
   one of <em>'howard'</em> or <em>'felbo'</em></li>
<li><code>deeptabular_gradual</code> (<code>bool</code>):
   boolean indicating if the <code>deeptabular</code> component will be fine tuned gradually</li>
<li><code>deeptabular_layers</code> (<code>Optional[Union[List[nn.Module], List[List[nn.Module]]]]</code>):
   List of pytorch modules indicating the layers of the
   <code>deeptabular</code> that will be fine tuned</li>
<li><code>deeptabular_max_lr</code> (<code>Union[float, List[float]]</code>):
   max lr for the <code>deeptabular</code> componet during fine tuning</li>
<li><code>deeptext_gradual</code> (<code>bool</code>):
   same as <code>deeptabular_gradual</code> but for the <code>deeptext</code> component</li>
<li><code>deeptext_layers</code> (<code>Optional[Union[List[nn.Module], List[List[nn.Module]]]]</code>):
   same as <code>deeptabular_gradual</code> but for the <code>deeptext</code> component.
   If there are multiple text columns/models, this should be a list of lists</li>
<li><code>deeptext_max_lr</code> (<code>Union[float, List[float]]</code>):
   same as <code>deeptabular_gradual</code> but for the <code>deeptext</code> component
   If there are multiple text columns/models, this should be a list of floats</li>
<li><code>deepimage_gradual</code> (<code>bool</code>):
   same as <code>deeptext_layers</code> but for the <code>deepimage</code> component</li>
<li><code>deepimage_layers</code> (<code>Optional[Union[List[nn.Module], List[List[nn.Module]]]]</code>):
   same as <code>deeptext_layers</code> but for the <code>deepimage</code> component</li>
<li><code>deepimage_max_lr</code> (<code>Union[float, List[float]]</code>):
    same as <code>deeptext_layers</code> but for the <code>deepimage</code> component</li>
</ul>
</li>
</ul>
              </div>
            </td>
          </tr>
      </tbody>
    </table>


<p><span class="doc-section-title">Examples:</span></p>
    <p>For a series of comprehensive examples on how to use the <code>fit</code> method, please see the
<a href="https://github.com/jrzaurin/pytorch-widedeep/tree/master/examples">Examples</a>
folder in the repo</p>

            <details class="quote">
              <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
              <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">273</span>
<span class="normal">274</span>
<span class="normal">275</span>
<span class="normal">276</span>
<span class="normal">277</span>
<span class="normal">278</span>
<span class="normal">279</span>
<span class="normal">280</span>
<span class="normal">281</span>
<span class="normal">282</span>
<span class="normal">283</span>
<span class="normal">284</span>
<span class="normal">285</span>
<span class="normal">286</span>
<span class="normal">287</span>
<span class="normal">288</span>
<span class="normal">289</span>
<span class="normal">290</span>
<span class="normal">291</span>
<span class="normal">292</span>
<span class="normal">293</span>
<span class="normal">294</span>
<span class="normal">295</span>
<span class="normal">296</span>
<span class="normal">297</span>
<span class="normal">298</span>
<span class="normal">299</span>
<span class="normal">300</span>
<span class="normal">301</span>
<span class="normal">302</span>
<span class="normal">303</span>
<span class="normal">304</span>
<span class="normal">305</span>
<span class="normal">306</span>
<span class="normal">307</span>
<span class="normal">308</span>
<span class="normal">309</span>
<span class="normal">310</span>
<span class="normal">311</span>
<span class="normal">312</span>
<span class="normal">313</span>
<span class="normal">314</span>
<span class="normal">315</span>
<span class="normal">316</span>
<span class="normal">317</span>
<span class="normal">318</span>
<span class="normal">319</span>
<span class="normal">320</span>
<span class="normal">321</span>
<span class="normal">322</span>
<span class="normal">323</span>
<span class="normal">324</span>
<span class="normal">325</span>
<span class="normal">326</span>
<span class="normal">327</span>
<span class="normal">328</span>
<span class="normal">329</span>
<span class="normal">330</span>
<span class="normal">331</span>
<span class="normal">332</span>
<span class="normal">333</span>
<span class="normal">334</span>
<span class="normal">335</span>
<span class="normal">336</span>
<span class="normal">337</span>
<span class="normal">338</span>
<span class="normal">339</span>
<span class="normal">340</span>
<span class="normal">341</span>
<span class="normal">342</span>
<span class="normal">343</span>
<span class="normal">344</span>
<span class="normal">345</span>
<span class="normal">346</span>
<span class="normal">347</span>
<span class="normal">348</span>
<span class="normal">349</span>
<span class="normal">350</span>
<span class="normal">351</span>
<span class="normal">352</span>
<span class="normal">353</span>
<span class="normal">354</span>
<span class="normal">355</span>
<span class="normal">356</span>
<span class="normal">357</span>
<span class="normal">358</span>
<span class="normal">359</span>
<span class="normal">360</span>
<span class="normal">361</span>
<span class="normal">362</span>
<span class="normal">363</span>
<span class="normal">364</span>
<span class="normal">365</span>
<span class="normal">366</span>
<span class="normal">367</span>
<span class="normal">368</span>
<span class="normal">369</span>
<span class="normal">370</span>
<span class="normal">371</span>
<span class="normal">372</span>
<span class="normal">373</span>
<span class="normal">374</span>
<span class="normal">375</span>
<span class="normal">376</span>
<span class="normal">377</span>
<span class="normal">378</span>
<span class="normal">379</span>
<span class="normal">380</span>
<span class="normal">381</span>
<span class="normal">382</span>
<span class="normal">383</span>
<span class="normal">384</span>
<span class="normal">385</span>
<span class="normal">386</span>
<span class="normal">387</span>
<span class="normal">388</span>
<span class="normal">389</span>
<span class="normal">390</span>
<span class="normal">391</span>
<span class="normal">392</span>
<span class="normal">393</span>
<span class="normal">394</span>
<span class="normal">395</span>
<span class="normal">396</span>
<span class="normal">397</span>
<span class="normal">398</span>
<span class="normal">399</span>
<span class="normal">400</span>
<span class="normal">401</span>
<span class="normal">402</span>
<span class="normal">403</span>
<span class="normal">404</span>
<span class="normal">405</span>
<span class="normal">406</span>
<span class="normal">407</span>
<span class="normal">408</span>
<span class="normal">409</span>
<span class="normal">410</span>
<span class="normal">411</span>
<span class="normal">412</span>
<span class="normal">413</span>
<span class="normal">414</span>
<span class="normal">415</span>
<span class="normal">416</span>
<span class="normal">417</span>
<span class="normal">418</span>
<span class="normal">419</span>
<span class="normal">420</span>
<span class="normal">421</span>
<span class="normal">422</span>
<span class="normal">423</span>
<span class="normal">424</span>
<span class="normal">425</span>
<span class="normal">426</span>
<span class="normal">427</span>
<span class="normal">428</span>
<span class="normal">429</span>
<span class="normal">430</span>
<span class="normal">431</span>
<span class="normal">432</span>
<span class="normal">433</span>
<span class="normal">434</span>
<span class="normal">435</span>
<span class="normal">436</span>
<span class="normal">437</span>
<span class="normal">438</span>
<span class="normal">439</span>
<span class="normal">440</span>
<span class="normal">441</span>
<span class="normal">442</span>
<span class="normal">443</span>
<span class="normal">444</span>
<span class="normal">445</span>
<span class="normal">446</span>
<span class="normal">447</span>
<span class="normal">448</span>
<span class="normal">449</span>
<span class="normal">450</span>
<span class="normal">451</span>
<span class="normal">452</span>
<span class="normal">453</span>
<span class="normal">454</span>
<span class="normal">455</span>
<span class="normal">456</span>
<span class="normal">457</span>
<span class="normal">458</span>
<span class="normal">459</span>
<span class="normal">460</span>
<span class="normal">461</span>
<span class="normal">462</span>
<span class="normal">463</span>
<span class="normal">464</span>
<span class="normal">465</span>
<span class="normal">466</span>
<span class="normal">467</span>
<span class="normal">468</span>
<span class="normal">469</span>
<span class="normal">470</span>
<span class="normal">471</span>
<span class="normal">472</span>
<span class="normal">473</span>
<span class="normal">474</span>
<span class="normal">475</span>
<span class="normal">476</span>
<span class="normal">477</span>
<span class="normal">478</span>
<span class="normal">479</span>
<span class="normal">480</span>
<span class="normal">481</span>
<span class="normal">482</span>
<span class="normal">483</span>
<span class="normal">484</span>
<span class="normal">485</span>
<span class="normal">486</span>
<span class="normal">487</span>
<span class="normal">488</span>
<span class="normal">489</span>
<span class="normal">490</span>
<span class="normal">491</span>
<span class="normal">492</span>
<span class="normal">493</span>
<span class="normal">494</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;finetune&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;warmup&quot;</span><span class="p">])</span>
<span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;train_dataloader&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;custom_dataloader&quot;</span><span class="p">])</span>
<span class="nd">@alias</span><span class="p">(</span><span class="s2">&quot;eval_dataloader&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;custom_eval_dataloader&quot;</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">fit</span><span class="p">(</span>  <span class="c1"># noqa: C901</span>
    <span class="bp">self</span><span class="p">,</span>
    <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_train</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_val</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">val_split</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">target</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">n_epochs</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
    <span class="n">validation_freq</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">32</span><span class="p">,</span>
    <span class="n">train_dataloader</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CustomDataLoader</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">eval_dataloader</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CustomDataLoader</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">feature_importance_sample_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">finetune</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
<span class="p">):</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Fit method.</span>

<span class="sd">    The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">    (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">    dictionaries (`X_train` or `X_val`).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `wide` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">    X_tab: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `deeptabular` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TabPreprocessor`. If multiple</span>
<span class="sd">        tabular models are used for different columns, this should be a</span>
<span class="sd">        list of numpy arrays</span>
<span class="sd">    X_text: Union[np.ndarray, List[np.ndarray]], Optional. default=None</span>
<span class="sd">        Input for the `deeptext` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TextPreprocessor`.</span>
<span class="sd">        If multiple text columns/models are used, this should be a list of</span>
<span class="sd">        numpy arrays</span>
<span class="sd">    X_img: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `deepimage` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.ImagePreprocessor`.</span>
<span class="sd">        If multiple image columns/models are used, this should be a list of</span>
<span class="sd">        numpy arrays</span>
<span class="sd">    X_train: Dict, Optional. default=None</span>
<span class="sd">        The training dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">        _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">        are the corresponding matrices. Note that of multiple text or image</span>
<span class="sd">        columns/models are used, the corresponding values should be lists</span>
<span class="sd">        of numpy arrays</span>
<span class="sd">    X_val: Dict, Optional. default=None</span>
<span class="sd">        The validation dataset can also be passed in a dictionary. Keys</span>
<span class="sd">        are _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_.</span>
<span class="sd">        Values are the corresponding matrices. Note that of multiple text</span>
<span class="sd">        or image columns/models are used, the corresponding values should</span>
<span class="sd">        be lists of numpy arrays</span>
<span class="sd">    val_split: float, Optional. default=None</span>
<span class="sd">        train/val split fraction</span>
<span class="sd">    target: np.ndarray, Optional. default=None</span>
<span class="sd">        target values</span>
<span class="sd">    n_epochs: int, default=1</span>
<span class="sd">        number of epochs</span>
<span class="sd">    validation_freq: int, default=1</span>
<span class="sd">        epochs validation frequency</span>
<span class="sd">    batch_size: int, default=32</span>
<span class="sd">        batch size</span>
<span class="sd">    custom_dataloader: `DataLoader`, Optional, default=None</span>
<span class="sd">        object of class `torch.utils.data.DataLoader`. Available</span>
<span class="sd">        predefined dataloaders are in `pytorch-widedeep.dataloaders`.If</span>
<span class="sd">        `None`, a standard torch `DataLoader` is used.</span>
<span class="sd">    finetune: bool, default=False</span>
<span class="sd">        fine-tune individual model components. This functionality can also</span>
<span class="sd">        be used to &#39;warm-up&#39; (and hence the alias `warmup`) individual</span>
<span class="sd">        components before the joined training starts, and hence its</span>
<span class="sd">        alias. See the Examples folder in the repo for more details</span>

<span class="sd">        `pytorch_widedeep` implements 3 fine-tune routines.</span>

<span class="sd">        - fine-tune all trainable layers at once. This routine is</span>
<span class="sd">          inspired by the work of Howard &amp; Sebastian Ruder 2018 in their</span>
<span class="sd">          [ULMfit paper](https://arxiv.org/abs/1801.06146). Using a</span>
<span class="sd">          Slanted Triangular learing (see</span>
<span class="sd">          [Leslie N. Smith paper](https://arxiv.org/pdf/1506.01186.pdf) ) ,</span>
<span class="sd">          the process is the following: *i*) the learning rate will</span>
<span class="sd">          gradually increase for 10% of the training steps from max_lr/10</span>
<span class="sd">          to max_lr. *ii*) It will then gradually decrease to max_lr/10</span>
<span class="sd">          for the remaining 90% of the steps. The optimizer used in the</span>
<span class="sd">          process is `Adam`.</span>

<span class="sd">        and two gradual fine-tune routines, where only certain layers are</span>
<span class="sd">        trained at a time.</span>

<span class="sd">        - The so called `Felbo` gradual fine-tune rourine, based on the the</span>
<span class="sd">          Felbo et al., 2017 [DeepEmoji paper](https://arxiv.org/abs/1708.00524).</span>
<span class="sd">        - The `Howard` routine based on the work of Howard &amp; Sebastian Ruder 2018 in their</span>
<span class="sd">          [ULMfit paper](https://arxiv.org/abs/1801.06146&gt;).</span>

<span class="sd">        For details on how these routines work, please see the Examples</span>
<span class="sd">        section in this documentation and the Examples folder in the repo. &lt;br/&gt;</span>
<span class="sd">        Param Alias: `warmup`</span>

<span class="sd">    Other Parameters</span>
<span class="sd">    ----------------</span>
<span class="sd">    **kwargs:</span>
<span class="sd">        Other keyword arguments are:</span>

<span class="sd">        - **DataLoader related parameters**:&lt;br/&gt;</span>
<span class="sd">            For example,  `sampler`, `batch_sampler`, `collate_fn`, etc.</span>
<span class="sd">            Please, see the pytorch</span>
<span class="sd">            [DataLoader docs](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader)</span>
<span class="sd">            for details.</span>

<span class="sd">        - **Finetune related parameters**:&lt;br/&gt;</span>
<span class="sd">            see the source code at `pytorch_widedeep._finetune`. Namely, these are:</span>

<span class="sd">            - `finetune_epochs` (`int`):</span>
<span class="sd">                number of epochs use for fine tuning</span>
<span class="sd">            - `finetune_max_lr` (`float`):</span>
<span class="sd">               max lr during fine tuning</span>
<span class="sd">            - `routine` (`str`):</span>
<span class="sd">               one of _&#39;howard&#39;_ or _&#39;felbo&#39;_</span>
<span class="sd">            - `deeptabular_gradual` (`bool`):</span>
<span class="sd">               boolean indicating if the `deeptabular` component will be fine tuned gradually</span>
<span class="sd">            - `deeptabular_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">               List of pytorch modules indicating the layers of the</span>
<span class="sd">               `deeptabular` that will be fine tuned</span>
<span class="sd">            - `deeptabular_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">               max lr for the `deeptabular` componet during fine tuning</span>
<span class="sd">            - `deeptext_gradual` (`bool`):</span>
<span class="sd">               same as `deeptabular_gradual` but for the `deeptext` component</span>
<span class="sd">            - `deeptext_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">               same as `deeptabular_gradual` but for the `deeptext` component.</span>
<span class="sd">               If there are multiple text columns/models, this should be a list of lists</span>
<span class="sd">            - `deeptext_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">               same as `deeptabular_gradual` but for the `deeptext` component</span>
<span class="sd">               If there are multiple text columns/models, this should be a list of floats</span>
<span class="sd">            - `deepimage_gradual` (`bool`):</span>
<span class="sd">               same as `deeptext_layers` but for the `deepimage` component</span>
<span class="sd">            - `deepimage_layers` (`Optional[Union[List[nn.Module], List[List[nn.Module]]]]`):</span>
<span class="sd">               same as `deeptext_layers` but for the `deepimage` component</span>
<span class="sd">            - `deepimage_max_lr` (`Union[float, List[float]]`):</span>
<span class="sd">                same as `deeptext_layers` but for the `deepimage` component</span>

<span class="sd">    Examples</span>
<span class="sd">    --------</span>

<span class="sd">    For a series of comprehensive examples on how to use the `fit` method, please see the</span>
<span class="sd">    [Examples](https://github.com/jrzaurin/pytorch-widedeep/tree/master/examples)</span>
<span class="sd">    folder in the repo</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">dataloader_args</span><span class="p">,</span> <span class="n">finetune_args</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extract_kwargs</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">batch_size</span> <span class="o">=</span> <span class="n">batch_size</span>
    <span class="n">train_set</span><span class="p">,</span> <span class="n">eval_set</span> <span class="o">=</span> <span class="n">wd_train_val_split</span><span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">seed</span><span class="p">,</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">,</span>  <span class="c1"># type: ignore</span>
        <span class="n">X_wide</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">,</span>
        <span class="n">X_train</span><span class="p">,</span>
        <span class="n">X_val</span><span class="p">,</span>
        <span class="n">val_split</span><span class="p">,</span>
        <span class="n">target</span><span class="p">,</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transforms</span><span class="p">,</span>
    <span class="p">)</span>
    <span class="n">train_loader</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_set_dataloader</span><span class="p">(</span>
        <span class="n">train_dataloader</span><span class="p">,</span> <span class="n">train_set</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">dataloader_args</span>
    <span class="p">)</span>
    <span class="n">eval_loader</span> <span class="o">=</span> <span class="p">(</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_dataloader</span><span class="p">(</span><span class="n">eval_dataloader</span><span class="p">,</span> <span class="n">eval_set</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">,</span> <span class="n">dataloader_args</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">eval_set</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
        <span class="k">else</span> <span class="kc">None</span>
    <span class="p">)</span>

    <span class="k">if</span> <span class="n">finetune</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">with_finetuning</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_do_finetune</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="o">**</span><span class="n">finetune_args</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span>
                <span class="s2">&quot;Fine-tuning (or warmup) of individual components completed. &quot;</span>
                <span class="s2">&quot;Training the whole model for </span><span class="si">{}</span><span class="s2"> epochs&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">n_epochs</span><span class="p">)</span>
            <span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">with_finetuning</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_train_begin</span><span class="p">(</span>
        <span class="p">{</span>
            <span class="s2">&quot;batch_size&quot;</span><span class="p">:</span> <span class="n">batch_size</span><span class="p">,</span>
            <span class="s2">&quot;train_steps&quot;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="n">train_loader</span><span class="p">),</span>
            <span class="s2">&quot;n_epochs&quot;</span><span class="p">:</span> <span class="n">n_epochs</span><span class="p">,</span>
        <span class="p">}</span>
    <span class="p">)</span>
    <span class="k">for</span> <span class="n">epoch</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_epochs</span><span class="p">):</span>
        <span class="n">epoch_logs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_train_epoch</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="n">epoch</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">eval_loader</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">epoch</span> <span class="o">%</span> <span class="n">validation_freq</span> <span class="o">==</span> <span class="p">(</span>
            <span class="n">validation_freq</span> <span class="o">-</span> <span class="mi">1</span>
        <span class="p">):</span>
            <span class="n">epoch_logs</span><span class="p">,</span> <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_eval_epoch</span><span class="p">(</span>
                <span class="n">eval_loader</span><span class="p">,</span> <span class="n">epoch_logs</span>
            <span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">on_epoch_end_metric</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reducelronplateau</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span>
                    <span class="s2">&quot;ReduceLROnPlateau scheduler can be used only with validation data.&quot;</span>
                <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_epoch_end</span><span class="p">(</span><span class="n">epoch</span><span class="p">,</span> <span class="n">epoch_logs</span><span class="p">,</span> <span class="n">on_epoch_end_metric</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">early_stop</span><span class="p">:</span>
            <span class="c1"># self.callback_container.on_train_end(epoch_logs)</span>
            <span class="k">break</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">callback_container</span><span class="o">.</span><span class="n">on_train_end</span><span class="p">(</span><span class="n">epoch_logs</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">feature_importance_sample_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance</span> <span class="o">=</span> <span class="n">FeatureImportance</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">device</span><span class="p">,</span> <span class="n">feature_importance_sample_size</span>
        <span class="p">)</span><span class="o">.</span><span class="n">feature_importance</span><span class="p">(</span><span class="n">train_loader</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_restore_best_weights</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
</code></pre></div></td></tr></table></div>
            </details>
    </div>

</div>

<div class="doc doc-object doc-function">


<h3 id="pytorch_widedeep.training.Trainer.predict" class="doc doc-heading">
            <span class="doc doc-object-name doc-function-name">predict</span>


<a href="#pytorch_widedeep.training.Trainer.predict" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">predict</span><span class="p">(</span>
    <span class="n">X_wide</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div>

    <div class="doc doc-contents ">

        <p>Returns the predictions</p>
<p>The input datasets can be passed either directly via numpy arrays
(<code>X_wide</code>, <code>X_tab</code>, <code>X_text</code> or <code>X_img</code>) or alternatively, in
a dictionary (<code>X_test</code>)</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>X_wide</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="numpy.ndarray">ndarray</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>wide</code> model component.
See <code>pytorch_widedeep.preprocessing.WidePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_tab</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptabular</code> model component.
See <code>pytorch_widedeep.preprocessing.TabPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_text</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptext</code> model component.
See <code>pytorch_widedeep.preprocessing.TextPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_img</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deepimage</code> model component.
See <code>pytorch_widedeep.preprocessing.ImagePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_test</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>The test dataset can also be passed in a dictionary. Keys are
<code>X_wide</code>, <em>'X_tab'</em>, <em>'X_text'</em>, <em>'X_img'</em> and <em>'target'</em>. Values
are the corresponding matrices.</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>batch_size</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[int]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>If a trainer is used to predict after having trained a model, the
<code>batch_size</code> needs to be defined as it will not be defined as
the <code>Trainer</code> is instantiated</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
      </tbody>
    </table>


    <p><span class="doc-section-title">Returns:</span></p>
    <table>
      <thead>
        <tr>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                  <code>np.ndarray:</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>array with the predictions</p>
              </div>
            </td>
          </tr>
      </tbody>
    </table>

            <details class="quote">
              <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
              <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">496</span>
<span class="normal">497</span>
<span class="normal">498</span>
<span class="normal">499</span>
<span class="normal">500</span>
<span class="normal">501</span>
<span class="normal">502</span>
<span class="normal">503</span>
<span class="normal">504</span>
<span class="normal">505</span>
<span class="normal">506</span>
<span class="normal">507</span>
<span class="normal">508</span>
<span class="normal">509</span>
<span class="normal">510</span>
<span class="normal">511</span>
<span class="normal">512</span>
<span class="normal">513</span>
<span class="normal">514</span>
<span class="normal">515</span>
<span class="normal">516</span>
<span class="normal">517</span>
<span class="normal">518</span>
<span class="normal">519</span>
<span class="normal">520</span>
<span class="normal">521</span>
<span class="normal">522</span>
<span class="normal">523</span>
<span class="normal">524</span>
<span class="normal">525</span>
<span class="normal">526</span>
<span class="normal">527</span>
<span class="normal">528</span>
<span class="normal">529</span>
<span class="normal">530</span>
<span class="normal">531</span>
<span class="normal">532</span>
<span class="normal">533</span>
<span class="normal">534</span>
<span class="normal">535</span>
<span class="normal">536</span>
<span class="normal">537</span>
<span class="normal">538</span>
<span class="normal">539</span>
<span class="normal">540</span>
<span class="normal">541</span>
<span class="normal">542</span>
<span class="normal">543</span>
<span class="normal">544</span>
<span class="normal">545</span>
<span class="normal">546</span>
<span class="normal">547</span>
<span class="normal">548</span>
<span class="normal">549</span>
<span class="normal">550</span>
<span class="normal">551</span>
<span class="normal">552</span>
<span class="normal">553</span>
<span class="normal">554</span>
<span class="normal">555</span>
<span class="normal">556</span>
<span class="normal">557</span>
<span class="normal">558</span>
<span class="normal">559</span>
<span class="normal">560</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">predict</span><span class="p">(</span>  <span class="c1"># type: ignore[override, return]</span>
    <span class="bp">self</span><span class="p">,</span>
    <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predictions</span>

<span class="sd">    The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">    (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">    a dictionary (`X_test`)</span>


<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `wide` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">    X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptabular` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">    X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptext` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">    X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deepimage` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">    X_test: Dict, Optional. default=None</span>
<span class="sd">        The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">        `X_wide`, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">        are the corresponding matrices.</span>
<span class="sd">    batch_size: int, default = 256</span>
<span class="sd">        If a trainer is used to predict after having trained a model, the</span>
<span class="sd">        `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">        the `Trainer` is instantiated</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    np.ndarray:</span>
<span class="sd">        array with the predictions</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span><span class="n">X_wide</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">,</span> <span class="n">X_text</span><span class="p">,</span> <span class="n">X_img</span><span class="p">,</span> <span class="n">X_test</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">preds</span> <span class="o">&gt;</span> <span class="mf">0.5</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s2">&quot;int&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;qregression&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">preds</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>  <span class="c1"># type: ignore[return-value]</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">loss_fn</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">in</span> <span class="p">[</span>
            <span class="s2">&quot;MultiTargetClassificationLoss&quot;</span><span class="p">,</span>
            <span class="s2">&quot;MutilTargetRegressionAndClassificationLoss&quot;</span><span class="p">,</span>
        <span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;MultiTargetClassificationLoss and MutilTargetRegressionAndClassificationLoss &quot;</span>
                <span class="s2">&quot;are not supported by predict method. Please use predict_proba method instead.&quot;</span>
            <span class="p">)</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
</code></pre></div></td></tr></table></div>
            </details>
    </div>

</div>

<div class="doc doc-object doc-function">


<h3 id="pytorch_widedeep.training.Trainer.predict_uncertainty" class="doc doc-heading">
            <span class="doc doc-object-name doc-function-name">predict_uncertainty</span>


<a href="#pytorch_widedeep.training.Trainer.predict_uncertainty" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">predict_uncertainty</span><span class="p">(</span>
    <span class="n">X_wide</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">uncertainty_granularity</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div>

    <div class="doc doc-contents ">

        <p>Returns the predicted ucnertainty of the model for the test dataset
using a Monte Carlo method during which dropout layers are activated
in the evaluation/prediction phase and each sample is predicted N
times (<code>uncertainty_granularity</code> times).</p>
<p>This is based on
<a href="https://arxiv.org/abs/1506.02142?context=stat">Dropout as a Bayesian Approximation: Representing
Model Uncertainty in Deep Learning</a>.</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>X_wide</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="numpy.ndarray">ndarray</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>wide</code> model component.
See <code>pytorch_widedeep.preprocessing.WidePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_tab</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptabular</code> model component.
See <code>pytorch_widedeep.preprocessing.TabPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_text</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptext</code> model component.
See <code>pytorch_widedeep.preprocessing.TextPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_img</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deepimage</code> model component.
See <code>pytorch_widedeep.preprocessing.ImagePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_test</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>The test dataset can also be passed in a dictionary. Keys are
<em>'X_wide'</em>, <em>'X_tab'</em>, <em>'X_text'</em>, <em>'X_img'</em> and <em>'target'</em>. Values
are the corresponding matrices.</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>batch_size</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[int]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>If a trainer is used to predict after having trained a model, the
<code>batch_size</code> needs to be defined as it will not be defined as
the <code>Trainer</code> is instantiated</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>uncertainty_granularity</code>
            </td>
            <td>
                  <code>int</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>number of times the model does prediction for each sample</p>
              </div>
            </td>
            <td>
                  <code>1000</code>
            </td>
          </tr>
      </tbody>
    </table>


    <p><span class="doc-section-title">Returns:</span></p>
    <table>
      <thead>
        <tr>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                  <code>np.ndarray:</code>
            </td>
            <td>
              <div class="doc-md-description">
                <ul>
<li>if <code>method = regression</code>, it will return an array with <code>(max, min, mean, stdev)</code>
  values for each sample.</li>
<li>if <code>method = binary</code> it will return an array with
  <code>(mean_cls_0_prob, mean_cls_1_prob, predicted_cls)</code> for each sample.</li>
<li>if <code>method = multiclass</code> it will return an array with
  <code>(mean_cls_0_prob, mean_cls_1_prob, mean_cls_2_prob, ... , predicted_cls)</code>
  values for each sample.</li>
</ul>
              </div>
            </td>
          </tr>
      </tbody>
    </table>

            <details class="quote">
              <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
              <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">562</span>
<span class="normal">563</span>
<span class="normal">564</span>
<span class="normal">565</span>
<span class="normal">566</span>
<span class="normal">567</span>
<span class="normal">568</span>
<span class="normal">569</span>
<span class="normal">570</span>
<span class="normal">571</span>
<span class="normal">572</span>
<span class="normal">573</span>
<span class="normal">574</span>
<span class="normal">575</span>
<span class="normal">576</span>
<span class="normal">577</span>
<span class="normal">578</span>
<span class="normal">579</span>
<span class="normal">580</span>
<span class="normal">581</span>
<span class="normal">582</span>
<span class="normal">583</span>
<span class="normal">584</span>
<span class="normal">585</span>
<span class="normal">586</span>
<span class="normal">587</span>
<span class="normal">588</span>
<span class="normal">589</span>
<span class="normal">590</span>
<span class="normal">591</span>
<span class="normal">592</span>
<span class="normal">593</span>
<span class="normal">594</span>
<span class="normal">595</span>
<span class="normal">596</span>
<span class="normal">597</span>
<span class="normal">598</span>
<span class="normal">599</span>
<span class="normal">600</span>
<span class="normal">601</span>
<span class="normal">602</span>
<span class="normal">603</span>
<span class="normal">604</span>
<span class="normal">605</span>
<span class="normal">606</span>
<span class="normal">607</span>
<span class="normal">608</span>
<span class="normal">609</span>
<span class="normal">610</span>
<span class="normal">611</span>
<span class="normal">612</span>
<span class="normal">613</span>
<span class="normal">614</span>
<span class="normal">615</span>
<span class="normal">616</span>
<span class="normal">617</span>
<span class="normal">618</span>
<span class="normal">619</span>
<span class="normal">620</span>
<span class="normal">621</span>
<span class="normal">622</span>
<span class="normal">623</span>
<span class="normal">624</span>
<span class="normal">625</span>
<span class="normal">626</span>
<span class="normal">627</span>
<span class="normal">628</span>
<span class="normal">629</span>
<span class="normal">630</span>
<span class="normal">631</span>
<span class="normal">632</span>
<span class="normal">633</span>
<span class="normal">634</span>
<span class="normal">635</span>
<span class="normal">636</span>
<span class="normal">637</span>
<span class="normal">638</span>
<span class="normal">639</span>
<span class="normal">640</span>
<span class="normal">641</span>
<span class="normal">642</span>
<span class="normal">643</span>
<span class="normal">644</span>
<span class="normal">645</span>
<span class="normal">646</span>
<span class="normal">647</span>
<span class="normal">648</span>
<span class="normal">649</span>
<span class="normal">650</span>
<span class="normal">651</span>
<span class="normal">652</span>
<span class="normal">653</span>
<span class="normal">654</span>
<span class="normal">655</span>
<span class="normal">656</span>
<span class="normal">657</span>
<span class="normal">658</span>
<span class="normal">659</span>
<span class="normal">660</span>
<span class="normal">661</span>
<span class="normal">662</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">predict_uncertainty</span><span class="p">(</span>  <span class="c1"># type: ignore[return]</span>
    <span class="bp">self</span><span class="p">,</span>
    <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">uncertainty_granularity</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predicted ucnertainty of the model for the test dataset</span>
<span class="sd">    using a Monte Carlo method during which dropout layers are activated</span>
<span class="sd">    in the evaluation/prediction phase and each sample is predicted N</span>
<span class="sd">    times (`uncertainty_granularity` times).</span>

<span class="sd">    This is based on</span>
<span class="sd">    [Dropout as a Bayesian Approximation: Representing</span>
<span class="sd">    Model Uncertainty in Deep Learning](https://arxiv.org/abs/1506.02142?context=stat).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `wide` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">    X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptabular` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">    X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptext` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">    X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deepimage` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">    X_test: Dict, Optional. default=None</span>
<span class="sd">        The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">        _&#39;X_wide&#39;_, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">        are the corresponding matrices.</span>
<span class="sd">    batch_size: int, default = 256</span>
<span class="sd">        If a trainer is used to predict after having trained a model, the</span>
<span class="sd">        `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">        the `Trainer` is instantiated</span>
<span class="sd">    uncertainty_granularity: int default = 1000</span>
<span class="sd">        number of times the model does prediction for each sample</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    np.ndarray:</span>
<span class="sd">        - if `method = regression`, it will return an array with `(max, min, mean, stdev)`</span>
<span class="sd">          values for each sample.</span>
<span class="sd">        - if `method = binary` it will return an array with</span>
<span class="sd">          `(mean_cls_0_prob, mean_cls_1_prob, predicted_cls)` for each sample.</span>
<span class="sd">        - if `method = multiclass` it will return an array with</span>
<span class="sd">          `(mean_cls_0_prob, mean_cls_1_prob, mean_cls_2_prob, ... , predicted_cls)`</span>
<span class="sd">          values for each sample.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span>
        <span class="n">X_wide</span><span class="p">,</span>
        <span class="n">X_tab</span><span class="p">,</span>
        <span class="n">X_text</span><span class="p">,</span>
        <span class="n">X_img</span><span class="p">,</span>
        <span class="n">X_test</span><span class="p">,</span>
        <span class="n">batch_size</span><span class="p">,</span>
        <span class="n">uncertainty_granularity</span><span class="p">,</span>
        <span class="n">uncertainty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="p">)</span>
    <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
    <span class="n">samples_num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">uncertainty_granularity</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;regression&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="p">(</span>
                <span class="n">preds</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                <span class="n">preds</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
                <span class="n">preds</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span>
            <span class="p">)</span>
        <span class="p">)</span><span class="o">.</span><span class="n">T</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;qregression&quot;</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
            <span class="s2">&quot;Currently predict_uncertainty is not supported for qregression method&quot;</span>
        <span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">))</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">probs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">3</span><span class="p">])</span>
        <span class="n">probs</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">preds</span>
        <span class="n">probs</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">preds</span>
        <span class="k">return</span> <span class="n">probs</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">uncertainty_granularity</span><span class="p">,</span> <span class="n">samples_num</span><span class="p">,</span> <span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">preds</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">preds</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">preds</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
        <span class="k">return</span> <span class="n">preds</span>

    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
            <span class="s2">&quot;Currently predict_uncertainty is not supported for multitarget method&quot;</span>
        <span class="p">)</span>
</code></pre></div></td></tr></table></div>
            </details>
    </div>

</div>

<div class="doc doc-object doc-function">


<h3 id="pytorch_widedeep.training.Trainer.predict_proba" class="doc doc-heading">
            <span class="doc doc-object-name doc-function-name">predict_proba</span>


<a href="#pytorch_widedeep.training.Trainer.predict_proba" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">predict_proba</span><span class="p">(</span>
    <span class="n">X_wide</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div>

    <div class="doc doc-contents ">

        <p>Returns the predicted probabilities for the test dataset for  binary
and multiclass methods</p>
<p>The input datasets can be passed either directly via numpy arrays
(<code>X_wide</code>, <code>X_tab</code>, <code>X_text</code> or <code>X_img</code>) or alternatively, in
a dictionary (<code>X_test</code>)</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>X_wide</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="numpy.ndarray">ndarray</span>]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>wide</code> model component.
See <code>pytorch_widedeep.preprocessing.WidePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_tab</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptabular</code> model component.
See <code>pytorch_widedeep.preprocessing.TabPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_text</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deeptext</code> model component.
See <code>pytorch_widedeep.preprocessing.TextPreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_img</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Input for the <code>deepimage</code> model component.
See <code>pytorch_widedeep.preprocessing.ImagePreprocessor</code></p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>X_test</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[<span title="pytorch_widedeep.wdtypes.Dict">Dict</span>[str, <span title="pytorch_widedeep.wdtypes.Union">Union</span>[<span title="numpy.ndarray">ndarray</span>, <span title="pytorch_widedeep.wdtypes.List">List</span>[<span title="numpy.ndarray">ndarray</span>]]]]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>The test dataset can also be passed in a dictionary. Keys are
<code>X_wide</code>, <em>'X_tab'</em>, <em>'X_text'</em>, <em>'X_img'</em> and <em>'target'</em>. Values
are the corresponding matrices.</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>batch_size</code>
            </td>
            <td>
                  <code><span title="pytorch_widedeep.wdtypes.Optional">Optional</span>[int]</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>If a trainer is used to predict after having trained a model, the
<code>batch_size</code> needs to be defined as it will not be defined as
the <code>Trainer</code> is instantiated</p>
              </div>
            </td>
            <td>
                  <code>None</code>
            </td>
          </tr>
      </tbody>
    </table>


    <p><span class="doc-section-title">Returns:</span></p>
    <table>
      <thead>
        <tr>
          <th>Type</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                  <code><span title="numpy.ndarray">ndarray</span></code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>array with the probabilities per class</p>
              </div>
            </td>
          </tr>
      </tbody>
    </table>

            <details class="quote">
              <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
              <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">664</span>
<span class="normal">665</span>
<span class="normal">666</span>
<span class="normal">667</span>
<span class="normal">668</span>
<span class="normal">669</span>
<span class="normal">670</span>
<span class="normal">671</span>
<span class="normal">672</span>
<span class="normal">673</span>
<span class="normal">674</span>
<span class="normal">675</span>
<span class="normal">676</span>
<span class="normal">677</span>
<span class="normal">678</span>
<span class="normal">679</span>
<span class="normal">680</span>
<span class="normal">681</span>
<span class="normal">682</span>
<span class="normal">683</span>
<span class="normal">684</span>
<span class="normal">685</span>
<span class="normal">686</span>
<span class="normal">687</span>
<span class="normal">688</span>
<span class="normal">689</span>
<span class="normal">690</span>
<span class="normal">691</span>
<span class="normal">692</span>
<span class="normal">693</span>
<span class="normal">694</span>
<span class="normal">695</span>
<span class="normal">696</span>
<span class="normal">697</span>
<span class="normal">698</span>
<span class="normal">699</span>
<span class="normal">700</span>
<span class="normal">701</span>
<span class="normal">702</span>
<span class="normal">703</span>
<span class="normal">704</span>
<span class="normal">705</span>
<span class="normal">706</span>
<span class="normal">707</span>
<span class="normal">708</span>
<span class="normal">709</span>
<span class="normal">710</span>
<span class="normal">711</span>
<span class="normal">712</span>
<span class="normal">713</span>
<span class="normal">714</span>
<span class="normal">715</span>
<span class="normal">716</span>
<span class="normal">717</span>
<span class="normal">718</span>
<span class="normal">719</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">predict_proba</span><span class="p">(</span>  <span class="c1"># type: ignore[override, return]  # noqa: C901</span>
    <span class="bp">self</span><span class="p">,</span>
    <span class="n">X_wide</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_tab</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_text</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_img</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">X_test</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">List</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
    <span class="n">batch_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Returns the predicted probabilities for the test dataset for  binary</span>
<span class="sd">    and multiclass methods</span>

<span class="sd">    The input datasets can be passed either directly via numpy arrays</span>
<span class="sd">    (`X_wide`, `X_tab`, `X_text` or `X_img`) or alternatively, in</span>
<span class="sd">    a dictionary (`X_test`)</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    X_wide: np.ndarray, Optional. default=None</span>
<span class="sd">        Input for the `wide` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.WidePreprocessor`</span>
<span class="sd">    X_tab: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptabular` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TabPreprocessor`</span>
<span class="sd">    X_text: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deeptext` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.TextPreprocessor`</span>
<span class="sd">    X_img: np.ndarray or List[np.ndarray], Optional. default=None</span>
<span class="sd">        Input for the `deepimage` model component.</span>
<span class="sd">        See `pytorch_widedeep.preprocessing.ImagePreprocessor`</span>
<span class="sd">    X_test: Dict, Optional. default=None</span>
<span class="sd">        The test dataset can also be passed in a dictionary. Keys are</span>
<span class="sd">        `X_wide`, _&#39;X_tab&#39;_, _&#39;X_text&#39;_, _&#39;X_img&#39;_ and _&#39;target&#39;_. Values</span>
<span class="sd">        are the corresponding matrices.</span>
<span class="sd">    batch_size: int, default = 256</span>
<span class="sd">        If a trainer is used to predict after having trained a model, the</span>
<span class="sd">        `batch_size` needs to be defined as it will not be defined as</span>
<span class="sd">        the `Trainer` is instantiated</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    np.ndarray</span>
<span class="sd">        array with the probabilities per class</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">preds_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_predict</span><span class="p">(</span><span class="n">X_wide</span><span class="p">,</span> <span class="n">X_tab</span><span class="p">,</span> <span class="n">X_text</span><span class="p">,</span> <span class="n">X_img</span><span class="p">,</span> <span class="n">X_test</span><span class="p">,</span> <span class="n">batch_size</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;binary&quot;</span><span class="p">:</span>
        <span class="n">preds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">probs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">([</span><span class="n">preds</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">2</span><span class="p">])</span>
        <span class="n">probs</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">preds</span>
        <span class="n">probs</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">preds</span>
        <span class="k">return</span> <span class="n">probs</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multiclass&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;multitarget&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="n">preds_l</span><span class="p">)</span>
</code></pre></div></td></tr></table></div>
            </details>
    </div>

</div>

<div class="doc doc-object doc-function">


<h3 id="pytorch_widedeep.training.Trainer.save" class="doc doc-heading">
            <span class="doc doc-object-name doc-function-name">save</span>


<a href="#pytorch_widedeep.training.Trainer.save" class="headerlink" title="Permanent link">&para;</a></h3>
<div class="doc-signature highlight"><pre><span></span><code><span class="nf">save</span><span class="p">(</span>
    <span class="n">path</span><span class="p">,</span>
    <span class="n">save_state_dict</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
    <span class="n">save_optimizer</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
    <span class="n">model_filename</span><span class="o">=</span><span class="s2">&quot;wd_model.pt&quot;</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div>

    <div class="doc doc-contents ">

        <p>Saves the model, training and evaluation history, and the
<code>feature_importance</code> attribute (if the <code>deeptabular</code> component is a
Tabnet model) to disk</p>
<p>The <code>Trainer</code> class is built so that it 'just' trains a model. With
that in mind, all the torch related parameters (such as optimizers,
learning rate schedulers, initializers, etc) have to be defined
externally and then passed to the <code>Trainer</code>. As a result, the
<code>Trainer</code> does not generate any attribute or additional data
products that need to be saved other than the <code>model</code> object itself,
which can be saved as any other torch model (e.g. <code>torch.save(model,
path)</code>).</p>
<p>The exception is Tabnet. If the <code>deeptabular</code> component is a Tabnet
model, an attribute (a dict) called <code>feature_importance</code> will be
created at the end of the training process. Therefore, a <code>save</code>
method was created that will save the feature importance dictionary
to a json file and, since we are here, the model weights, training
history and learning rate history.</p>


<p><span class="doc-section-title">Parameters:</span></p>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Type</th>
          <th>Description</th>
          <th>Default</th>
        </tr>
      </thead>
      <tbody>
          <tr class="doc-section-item">
            <td>
                <code>path</code>
            </td>
            <td>
                  <code>str</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>path to the directory where the model and the feature importance
attribute will be saved.</p>
              </div>
            </td>
            <td>
                <em>required</em>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>save_state_dict</code>
            </td>
            <td>
                  <code>bool</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Boolean indicating whether to save directly the model
(and optimizer) or the model's (and optimizer's) state
dictionary</p>
              </div>
            </td>
            <td>
                  <code>False</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>save_optimizer</code>
            </td>
            <td>
                  <code>bool</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>Boolean indicating whether to save the optimizer</p>
              </div>
            </td>
            <td>
                  <code>False</code>
            </td>
          </tr>
          <tr class="doc-section-item">
            <td>
                <code>model_filename</code>
            </td>
            <td>
                  <code>str</code>
            </td>
            <td>
              <div class="doc-md-description">
                <p>filename where the model weights will be store</p>
              </div>
            </td>
            <td>
                  <code>&#39;wd_model.pt&#39;</code>
            </td>
          </tr>
      </tbody>
    </table>

            <details class="quote">
              <summary>Source code in <code>pytorch_widedeep/training/trainer.py</code></summary>
              <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">732</span>
<span class="normal">733</span>
<span class="normal">734</span>
<span class="normal">735</span>
<span class="normal">736</span>
<span class="normal">737</span>
<span class="normal">738</span>
<span class="normal">739</span>
<span class="normal">740</span>
<span class="normal">741</span>
<span class="normal">742</span>
<span class="normal">743</span>
<span class="normal">744</span>
<span class="normal">745</span>
<span class="normal">746</span>
<span class="normal">747</span>
<span class="normal">748</span>
<span class="normal">749</span>
<span class="normal">750</span>
<span class="normal">751</span>
<span class="normal">752</span>
<span class="normal">753</span>
<span class="normal">754</span>
<span class="normal">755</span>
<span class="normal">756</span>
<span class="normal">757</span>
<span class="normal">758</span>
<span class="normal">759</span>
<span class="normal">760</span>
<span class="normal">761</span>
<span class="normal">762</span>
<span class="normal">763</span>
<span class="normal">764</span>
<span class="normal">765</span>
<span class="normal">766</span>
<span class="normal">767</span>
<span class="normal">768</span>
<span class="normal">769</span>
<span class="normal">770</span>
<span class="normal">771</span>
<span class="normal">772</span>
<span class="normal">773</span>
<span class="normal">774</span>
<span class="normal">775</span>
<span class="normal">776</span>
<span class="normal">777</span>
<span class="normal">778</span>
<span class="normal">779</span>
<span class="normal">780</span>
<span class="normal">781</span>
<span class="normal">782</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">save</span><span class="p">(</span>
    <span class="bp">self</span><span class="p">,</span>
    <span class="n">path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
    <span class="n">save_state_dict</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">save_optimizer</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">model_filename</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;wd_model.pt&quot;</span><span class="p">,</span>
<span class="p">):</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Saves the model, training and evaluation history, and the</span>
<span class="sd">    `feature_importance` attribute (if the `deeptabular` component is a</span>
<span class="sd">    Tabnet model) to disk</span>

<span class="sd">    The `Trainer` class is built so that it &#39;just&#39; trains a model. With</span>
<span class="sd">    that in mind, all the torch related parameters (such as optimizers,</span>
<span class="sd">    learning rate schedulers, initializers, etc) have to be defined</span>
<span class="sd">    externally and then passed to the `Trainer`. As a result, the</span>
<span class="sd">    `Trainer` does not generate any attribute or additional data</span>
<span class="sd">    products that need to be saved other than the `model` object itself,</span>
<span class="sd">    which can be saved as any other torch model (e.g. `torch.save(model,</span>
<span class="sd">    path)`).</span>

<span class="sd">    The exception is Tabnet. If the `deeptabular` component is a Tabnet</span>
<span class="sd">    model, an attribute (a dict) called `feature_importance` will be</span>
<span class="sd">    created at the end of the training process. Therefore, a `save`</span>
<span class="sd">    method was created that will save the feature importance dictionary</span>
<span class="sd">    to a json file and, since we are here, the model weights, training</span>
<span class="sd">    history and learning rate history.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    path: str</span>
<span class="sd">        path to the directory where the model and the feature importance</span>
<span class="sd">        attribute will be saved.</span>
<span class="sd">    save_state_dict: bool, default = False</span>
<span class="sd">        Boolean indicating whether to save directly the model</span>
<span class="sd">        (and optimizer) or the model&#39;s (and optimizer&#39;s) state</span>
<span class="sd">        dictionary</span>
<span class="sd">    save_optimizer: bool, default = False</span>
<span class="sd">        Boolean indicating whether to save the optimizer</span>
<span class="sd">    model_filename: str, Optional, default = &quot;wd_model.pt&quot;</span>
<span class="sd">        filename where the model weights will be store</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">_save_history</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">_save_model_and_optimizer</span><span class="p">(</span>
        <span class="n">path</span><span class="p">,</span> <span class="n">save_state_dict</span><span class="p">,</span> <span class="n">save_optimizer</span><span class="p">,</span> <span class="n">model_filename</span>
    <span class="p">)</span>

    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">is_tabnet</span><span class="p">:</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="o">/</span> <span class="s2">&quot;feature_importance.json&quot;</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fi</span><span class="p">:</span>
            <span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_importance</span><span class="p">,</span> <span class="n">fi</span><span class="p">)</span>
</code></pre></div></td></tr></table></div>
            </details>
    </div>

</div>



  </div>

    </div>

</div>








  <aside class="md-source-file">
    
    
    
      
  
  <span class="md-source-file__fact">
    <span class="md-icon" title="Contributors">
      
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 5.5A3.5 3.5 0 0 1 15.5 9a3.5 3.5 0 0 1-3.5 3.5A3.5 3.5 0 0 1 8.5 9 3.5 3.5 0 0 1 12 5.5M5 8c.56 0 1.08.15 1.53.42-.15 1.43.27 2.85 1.13 3.96C7.16 13.34 6.16 14 5 14a3 3 0 0 1-3-3 3 3 0 0 1 3-3m14 0a3 3 0 0 1 3 3 3 3 0 0 1-3 3c-1.16 0-2.16-.66-2.66-1.62a5.54 5.54 0 0 0 1.13-3.96c.45-.27.97-.42 1.53-.42M5.5 18.25c0-2.07 2.91-3.75 6.5-3.75s6.5 1.68 6.5 3.75V20h-13zM0 20v-1.5c0-1.39 1.89-2.56 4.45-2.9-.59.68-.95 1.62-.95 2.65V20zm24 0h-3.5v-1.75c0-1.03-.36-1.97-.95-2.65 2.56.34 4.45 1.51 4.45 2.9z"/></svg>
      
    </span>
    <nav>
      
        <a href="mailto:javierrodriguezzaurin@javiers-macbook-pro.local">Javier Rodriguez Zaurin</a>, 
        <a href="mailto:mulinka.pavol@gmail.com">Pavol Mulinka</a>
    </nav>
  </span>

    
    
  </aside>





                
              </article>
            </div>
          
          
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
        </div>
        
      </main>
      
        <footer class="md-footer">
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
    <div class="md-copyright__highlight">
      Javier Zaurin and Pavol Mulinka
    </div>
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
        <div class="md-social">
  
    
    
    
    
      
      
    
    <a href="https://jrzaurin.medium.com/" target="_blank" rel="noopener" title="jrzaurin.medium.com" class="md-social__link">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M180.5 74.262C80.813 74.262 0 155.633 0 256s80.819 181.738 180.5 181.738S361 356.373 361 256 280.191 74.262 180.5 74.262m288.25 10.646c-49.845 0-90.245 76.619-90.245 171.095s40.406 171.1 90.251 171.1 90.251-76.619 90.251-171.1H559c0-94.503-40.4-171.095-90.248-171.095Zm139.506 17.821c-17.526 0-31.735 68.628-31.735 153.274s14.2 153.274 31.735 153.274S640 340.631 640 256c0-84.649-14.215-153.271-31.742-153.271Z"/></svg>
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    
    <script id="__config" type="application/json">{"base": "..", "features": ["navigation.tabs", "navigation.tabs.sticky", "navigation.indexes", "navigation.expand", "toc.integrate"], "search": "../assets/javascripts/workers/search.6ce7567c.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
    
    
      <script src="../assets/javascripts/bundle.83f73b43.min.js"></script>
      
        <script src="../stylesheets/extra.js"></script>
      
        <script src="../javascripts/mathjax.js"></script>
      
        <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
      
        <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
      
    
  </body>
</html>